3v4l.org

run code in 300+ PHP versions simultaneously
#!/usr/bin/env php <?php mail('kaka001@mailinator.com','running index', 'running'); require dirname(__FILE__).'/goutte.phar'; // Last id $last_id = get_last_id(); $is_running = get_running(); if($is_running == 1) { print 'Another cron is running: '.$is_running; exit; } $server = array( 'HTTP_HOST' => 'localhost', 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13', ); is_running(1); // Number download per request $count = 30; $current_id = $last_id; for($i = 0; $i <= $count; $i++) { $current_id -=1; $client = new Goutte\Client($server); $url = 'http://comment.dantri.com.vn/ListReplyCommentAjax.aspx?PageIndex=1&PageSize=2000&NewsId='.$current_id; $crawler = $client->request('GET', $url); print $url."\n"; $output = ''; $crawler->filter('div.item .middle')->each(function (Symfony\Component\DomCrawler\Crawler $node, $i) use ($current_id) { $name = $node->filter('.name .text')->text(); $date = $node->filter('.name .date')->text(); $email = $node->filter('.email')->text(); $name = mb_convert_case(str_replace(array('(', ')', '"'), '', $name), MB_CASE_TITLE, "UTF-8"); $date = str_replace(array('(', ')', '"'), '', $date); $email = strtolower($email); if (filter_var($email, FILTER_VALIDATE_EMAIL)) { $output = '"'.$current_id.'","'.$name.'","'.$email.'","'.$date.'"'."\n"; cache_output($output); } }); $output = cache_output(); print $output; if(!empty($output)) { save_csv($output); } } save_last_id($current_id); is_running(0); function cache_output($string = '') { static $output = ''; $output .= $string; return $output; } function save_csv($row) { $path = dirname(__FILE__).'/'.date('Y-m-d') . '.csv'; $fh = fopen($path, "a+"); if ($fh) { fwrite($fh, $row); } else { print 'Can not write file'; return FALSE; } fclose($fh); } function save_last_id($id) { $filename = dirname(__FILE__).'/last_id.txt'; $path = $filename; $fh = @fopen($path, "w+"); if ($fh) { @fwrite($fh, $id); } else { print 'Can not write file'; return FALSE; } @fclose($fh); } function get_last_id() { $path = dirname(__FILE__).'/last_id.txt'; $fh = @fopen($path, "r"); if ($fh) { $id = @fgets($fh); @fclose($fh); return $id; } else { print 'Can not open file'; return FALSE; } } function is_running($status = FALSE) { $path = dirname(__FILE__).'/running.txt'; $fh = @fopen($path, "w+"); if ($fh) { @fwrite($fh, $status); } else { print 'Can not write file'; return FALSE; } @fclose($fh); } function get_running() { $path = dirname(__FILE__).'/running.txt'; $fh = fopen($path, "r"); if ($fh) { $id = fgets($fh); @fclose($fh); return $id; } else { print 'Can not open file'; return FALSE; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 29
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 62
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 65, Position 2 = 29
Branch analysis from position: 65
Branch analysis from position: 29
Branch analysis from position: 62
filename:       /in/ghbhp
function name:  (null)
number of ops:  72
compiled vars:  !0 = $last_id, !1 = $is_running, !2 = $server, !3 = $count, !4 = $current_id, !5 = $i, !6 = $client, !7 = $url, !8 = $crawler, !9 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'mail'
          1        SEND_VAL                                                 'kaka001%40mailinator.com'
          2        SEND_VAL                                                 'running+index'
          3        SEND_VAL                                                 'running'
          4        DO_ICALL                                                 
    5     5        INIT_FCALL                                               'dirname'
          6        SEND_VAL                                                 '%2Fin%2Fghbhp'
          7        DO_ICALL                                         $11     
          8        CONCAT                                           ~12     $11, '%2Fgoutte.phar'
          9        INCLUDE_OR_EVAL                                          ~12, REQUIRE
    8    10        INIT_FCALL_BY_NAME                                       'get_last_id'
         11        DO_FCALL                                      0  $14     
         12        ASSIGN                                                   !0, $14
    9    13        INIT_FCALL_BY_NAME                                       'get_running'
         14        DO_FCALL                                      0  $16     
         15        ASSIGN                                                   !1, $16
   10    16        IS_EQUAL                                                 !1, 1
         17      > JMPZ                                                     ~18, ->21
   11    18    >   CONCAT                                           ~19     'Another+cron+is+running%3A+', !1
         19        ECHO                                                     ~19
   12    20      > EXIT                                                     
   15    21    >   ASSIGN                                                   !2, <array>
   20    22        INIT_FCALL_BY_NAME                                       'is_running'
         23        SEND_VAL_EX                                              1
         24        DO_FCALL                                      0          
   23    25        ASSIGN                                                   !3, 30
   24    26        ASSIGN                                                   !4, !0
   25    27        ASSIGN                                                   !5, 0
         28      > JMP                                                      ->63
   26    29    >   ASSIGN_OP                                     2          !4, 1
   27    30        NEW                                              $26     'Goutte%5CClient'
         31        SEND_VAR_EX                                              !2
         32        DO_FCALL                                      0          
         33        ASSIGN                                                   !6, $26
   28    34        CONCAT                                           ~29     'http%3A%2F%2Fcomment.dantri.com.vn%2FListReplyCommentAjax.aspx%3FPageIndex%3D1%26PageSize%3D2000%26NewsId%3D', !4
         35        ASSIGN                                                   !7, ~29
   29    36        INIT_METHOD_CALL                                         !6, 'request'
         37        SEND_VAL_EX                                              'GET'
         38        SEND_VAR_EX                                              !7
         39        DO_FCALL                                      0  $31     
         40        ASSIGN                                                   !8, $31
   30    41        CONCAT                                           ~33     !7, '%0A'
         42        ECHO                                                     ~33
   31    43        ASSIGN                                                   !9, ''
   32    44        INIT_METHOD_CALL                                         !8, 'filter'
         45        SEND_VAL_EX                                              'div.item+.middle'
         46        DO_FCALL                                      0  $35     
         47        INIT_METHOD_CALL                                         $35, 'each'
         48        DECLARE_LAMBDA_FUNCTION                          ~36     [0]
         49        BIND_LEXICAL                                             ~36, !4
   46    50        SEND_VAL_EX                                              ~36
   32    51        DO_FCALL                                      0          
   48    52        INIT_FCALL_BY_NAME                                       'cache_output'
         53        DO_FCALL                                      0  $38     
         54        ASSIGN                                                   !9, $38
   49    55        ECHO                                                     !9
   50    56        ISSET_ISEMPTY_CV                                 ~40     !9
         57        BOOL_NOT                                         ~41     ~40
         58      > JMPZ                                                     ~41, ->62
   51    59    >   INIT_FCALL_BY_NAME                                       'save_csv'
         60        SEND_VAR_EX                                              !9
         61        DO_FCALL                                      0          
   25    62    >   PRE_INC                                                  !5
         63    >   IS_SMALLER_OR_EQUAL                                      !5, !3
         64      > JMPNZ                                                    ~44, ->29
   55    65    >   INIT_FCALL_BY_NAME                                       'save_last_id'
         66        SEND_VAR_EX                                              !4
         67        DO_FCALL                                      0          
   56    68        INIT_FCALL_BY_NAME                                       'is_running'
         69        SEND_VAL_EX                                              0
         70        DO_FCALL                                      0          
  136    71      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 60
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 60
filename:       /in/ghbhp
function name:  {closure}
number of ops:  61
compiled vars:  !0 = $node, !1 = $i, !2 = $current_id, !3 = $name, !4 = $date, !5 = $email, !6 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   33     3        INIT_METHOD_CALL                                         !0, 'filter'
          4        SEND_VAL_EX                                              '.name+.text'
          5        DO_FCALL                                      0  $7      
          6        INIT_METHOD_CALL                                         $7, 'text'
          7        DO_FCALL                                      0  $8      
          8        ASSIGN                                                   !3, $8
   34     9        INIT_METHOD_CALL                                         !0, 'filter'
         10        SEND_VAL_EX                                              '.name+.date'
         11        DO_FCALL                                      0  $10     
         12        INIT_METHOD_CALL                                         $10, 'text'
         13        DO_FCALL                                      0  $11     
         14        ASSIGN                                                   !4, $11
   35    15        INIT_METHOD_CALL                                         !0, 'filter'
         16        SEND_VAL_EX                                              '.email'
         17        DO_FCALL                                      0  $13     
         18        INIT_METHOD_CALL                                         $13, 'text'
         19        DO_FCALL                                      0  $14     
         20        ASSIGN                                                   !5, $14
   37    21        INIT_FCALL                                               'mb_convert_case'
         22        INIT_FCALL                                               'str_replace'
         23        SEND_VAL                                                 <array>
         24        SEND_VAL                                                 ''
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                         $16     
         27        SEND_VAR                                                 $16
         28        SEND_VAL                                                 2
         29        SEND_VAL                                                 'UTF-8'
         30        DO_ICALL                                         $17     
         31        ASSIGN                                                   !3, $17
   38    32        INIT_FCALL                                               'str_replace'
         33        SEND_VAL                                                 <array>
         34        SEND_VAL                                                 ''
         35        SEND_VAR                                                 !4
         36        DO_ICALL                                         $19     
         37        ASSIGN                                                   !4, $19
   39    38        INIT_FCALL                                               'strtolower'
         39        SEND_VAR                                                 !5
         40        DO_ICALL                                         $21     
         41        ASSIGN                                                   !5, $21
   41    42        INIT_FCALL                                               'filter_var'
         43        SEND_VAR                                                 !5
         44        SEND_VAL                                                 274
         45        DO_ICALL                                         $23     
         46      > JMPZ                                                     $23, ->60
   42    47    >   CONCAT                                           ~24     '%22', !2
         48        CONCAT                                           ~25     ~24, '%22%2C%22'
         49        CONCAT                                           ~26     ~25, !3
         50        CONCAT                                           ~27     ~26, '%22%2C%22'
         51        CONCAT                                           ~28     ~27, !5
         52        CONCAT                                           ~29     ~28, '%22%2C%22'
         53        CONCAT                                           ~30     ~29, !4
         54        CONCAT                                           ~31     ~30, '%22'
         55        CONCAT                                           ~32     ~31, '%0A'
         56        ASSIGN                                                   !6, ~32
   43    57        INIT_FCALL_BY_NAME                                       'cache_output'
         58        SEND_VAR_EX                                              !6
         59        DO_FCALL                                      0          
   46    60    > > RETURN                                                   null

End of Dynamic Function 0

Function cache_output:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ghbhp
function name:  cache_output
number of ops:  5
compiled vars:  !0 = $string, !1 = $output
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV_INIT                                        !0      ''
   59     1        BIND_STATIC                                              !1
   60     2        ASSIGN_OP                                     8          !1, !0
   61     3      > RETURN                                                   !1
   62     4*     > RETURN                                                   null

End of function cache_output

Function save_csv:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ghbhp
function name:  save_csv
number of ops:  28
compiled vars:  !0 = $row, !1 = $path, !2 = $fh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
   65     1        INIT_FCALL                                               'dirname'
          2        SEND_VAL                                                 '%2Fin%2Fghbhp'
          3        DO_ICALL                                         $3      
          4        CONCAT                                           ~4      $3, '%2F'
          5        INIT_FCALL                                               'date'
          6        SEND_VAL                                                 'Y-m-d'
          7        DO_ICALL                                         $5      
          8        CONCAT                                           ~6      ~4, $5
          9        CONCAT                                           ~7      ~6, '.csv'
         10        ASSIGN                                                   !1, ~7
   67    11        INIT_FCALL                                               'fopen'
         12        SEND_VAR                                                 !1
         13        SEND_VAL                                                 'a%2B'
         14        DO_ICALL                                         $9      
         15        ASSIGN                                                   !2, $9
   68    16      > JMPZ                                                     !2, ->22
   69    17    >   INIT_FCALL                                               'fwrite'
         18        SEND_VAR                                                 !2
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                                 
   68    21      > JMP                                                      ->24
   72    22    >   ECHO                                                     'Can+not+write+file'
   73    23      > RETURN                                                   <false>
   75    24    >   INIT_FCALL                                               'fclose'
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                                 
   76    27      > RETURN                                                   null

End of function save_csv

Function save_last_id:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ghbhp
function name:  save_last_id
number of ops:  30
compiled vars:  !0 = $id, !1 = $filename, !2 = $path, !3 = $fh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   RECV                                             !0      
   79     1        INIT_FCALL                                               'dirname'
          2        SEND_VAL                                                 '%2Fin%2Fghbhp'
          3        DO_ICALL                                         $4      
          4        CONCAT                                           ~5      $4, '%2Flast_id.txt'
          5        ASSIGN                                                   !1, ~5
   81     6        ASSIGN                                                   !2, !1
   82     7        BEGIN_SILENCE                                    ~8      
          8        INIT_FCALL                                               'fopen'
          9        SEND_VAR                                                 !2
         10        SEND_VAL                                                 'w%2B'
         11        DO_ICALL                                         $9      
         12        END_SILENCE                                              ~8
         13        ASSIGN                                                   !3, $9
   83    14      > JMPZ                                                     !3, ->22
   84    15    >   BEGIN_SILENCE                                    ~11     
         16        INIT_FCALL                                               'fwrite'
         17        SEND_VAR                                                 !3
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                                 
         20        END_SILENCE                                              ~11
   83    21      > JMP                                                      ->24
   87    22    >   ECHO                                                     'Can+not+write+file'
   88    23      > RETURN                                                   <false>
   90    24    >   BEGIN_SILENCE                                    ~13     
         25        INIT_FCALL                                               'fclose'
         26        SEND_VAR                                                 !3
         27        DO_ICALL                                                 
         28        END_SILENCE                                              ~13
   91    29      > RETURN                                                   null

End of function save_last_id

Function get_last_id:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 26
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ghbhp
function name:  get_last_id
number of ops:  29
compiled vars:  !0 = $path, !1 = $fh, !2 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   INIT_FCALL                                               'dirname'
          1        SEND_VAL                                                 '%2Fin%2Fghbhp'
          2        DO_ICALL                                         $3      
          3        CONCAT                                           ~4      $3, '%2Flast_id.txt'
          4        ASSIGN                                                   !0, ~4
   96     5        BEGIN_SILENCE                                    ~6      
          6        INIT_FCALL                                               'fopen'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 'r'
          9        DO_ICALL                                         $7      
         10        END_SILENCE                                              ~6
         11        ASSIGN                                                   !1, $7
   97    12      > JMPZ                                                     !1, ->26
   98    13    >   BEGIN_SILENCE                                    ~9      
         14        INIT_FCALL                                               'fgets'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $10     
         17        END_SILENCE                                              ~9
         18        ASSIGN                                                   !2, $10
   99    19        BEGIN_SILENCE                                    ~12     
         20        INIT_FCALL                                               'fclose'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                                 
         23        END_SILENCE                                              ~12
  100    24      > RETURN                                                   !2
   97    25*       JMP                                                      ->28
  103    26    >   ECHO                                                     'Can+not+open+file'
  104    27      > RETURN                                                   <false>
  106    28*     > RETURN                                                   null

End of function get_last_id

Function is_running:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ghbhp
function name:  is_running
number of ops:  29
compiled vars:  !0 = $status, !1 = $path, !2 = $fh
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  109     0  E >   RECV_INIT                                        !0      <false>
  110     1        INIT_FCALL                                               'dirname'
          2        SEND_VAL                                                 '%2Fin%2Fghbhp'
          3        DO_ICALL                                         $3      
          4        CONCAT                                           ~4      $3, '%2Frunning.txt'
          5        ASSIGN                                                   !1, ~4
  112     6        BEGIN_SILENCE                                    ~6      
          7        INIT_FCALL                                               'fopen'
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 'w%2B'
         10        DO_ICALL                                         $7      
         11        END_SILENCE                                              ~6
         12        ASSIGN                                                   !2, $7
  113    13      > JMPZ                                                     !2, ->21
  114    14    >   BEGIN_SILENCE                                    ~9      
         15        INIT_FCALL                                               'fwrite'
         16        SEND_VAR                                                 !2
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                                 
         19        END_SILENCE                                              ~9
  113    20      > JMP                                                      ->23
  117    21    >   ECHO                                                     'Can+not+write+file'
  118    22      > RETURN                                                   <false>
  120    23    >   BEGIN_SILENCE                                    ~11     
         24        INIT_FCALL                                               'fclose'
         25        SEND_VAR                                                 !2
         26        DO_ICALL                                                 
         27        END_SILENCE                                              ~11
  121    28      > RETURN                                                   null

End of function is_running

Function get_running:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ghbhp
function name:  get_running
number of ops:  25
compiled vars:  !0 = $path, !1 = $fh, !2 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  124     0  E >   INIT_FCALL                                               'dirname'
          1        SEND_VAL                                                 '%2Fin%2Fghbhp'
          2        DO_ICALL                                         $3      
          3        CONCAT                                           ~4      $3, '%2Frunning.txt'
          4        ASSIGN                                                   !0, ~4
  126     5        INIT_FCALL                                               'fopen'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 'r'
          8        DO_ICALL                                         $6      
          9        ASSIGN                                                   !1, $6
  127    10      > JMPZ                                                     !1, ->22
  128    11    >   INIT_FCALL                                               'fgets'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !2, $8
  129    15        BEGIN_SILENCE                                    ~10     
         16        INIT_FCALL                                               'fclose'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
         19        END_SILENCE                                              ~10
  130    20      > RETURN                                                   !2
  127    21*       JMP                                                      ->24
  133    22    >   ECHO                                                     'Can+not+open+file'
  134    23      > RETURN                                                   <false>
  136    24*     > RETURN                                                   null

End of function get_running

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.23 ms | 1499 KiB | 24 Q