3v4l.org

run code in 300+ PHP versions simultaneously
<?php for($i=0;$i<=100;++$i){ //$urls[] = 'http://search.yahoo.com/?q='.$i.'a'; //&num=100 $urls[] = 'http://www.goo598541e'.$i.'.com/search?q='.$i.'ab'; //$urls[] = 'http://www.google.com/search?q='.$i.'a&num=100'; } $start = microtime(true); rolling_curl($urls, $thr , "cb"); $end = microtime(true); $time = $end - $start; echo '<b>Total time '.round($time , 2).' seconds</b><br />'."\n"; function rolling_curl($urls, $rolling_window = 2 , $callback, $custom_options = null) { // make sure the rolling window isn't greater than the # of urls $rolling_window = (count($urls) < $rolling_window) ? count($urls) : $rolling_window; //$running = null; $master = curl_multi_init(); $curl_arr = array(); // add additional curl options here $std_options = array( CURLOPT_RETURNTRANSFER => true, //CURLOPT_FAILONERROR=> true, CURLOPT_CONNECTTIMEOUT_MS=> 2000, CURLOPT_TIMEOUT_MS=> 2000, CURLOPT_FRESH_CONNECT=> true, CURLOPT_FORBID_REUSE=> true ); $options = ($custom_options) ? ($std_options + $custom_options) : $std_options; // start the first batch of requests for ($i = 0; $i < $rolling_window; ++$i) { $ch = curl_init(); $options[CURLOPT_URL] = $urls[$i]; curl_setopt_array($ch,$options); curl_multi_add_handle($master, $ch); } do { while(($execrun = curl_multi_exec($master, $running)) == CURLM_CALL_MULTI_PERFORM ); if($execrun != CURLM_OK) break; // a request was just completed -- find out which one while($done = curl_multi_info_read($master)) { $info = curl_getinfo($done['handle']); if ($info['http_code'] == 200) { $output = curl_multi_getcontent($done['handle']); // request successful. process output using the callback function. $callback($output , $info['url'] , $start); // start a new request (it's important to do this before removing the old one) if( isset($urls[$i+1]) ) { $ch = curl_init(); $options[CURLOPT_URL] = $urls[$i+1]; ++$i; // increment i curl_setopt_array($ch,$options); curl_multi_add_handle($master, $ch); // remove the curl handle that just completed curl_multi_remove_handle($master, $done['handle']); } else curl_multi_remove_handle($master, $done['handle']); } else { echo curl_error($done['handle'])." - ".$info['url']." <br/>\n\r"; //echo $info['url']." -> error<br>\n\r"; //print_r($info); // request failed. add error handling. if( isset($urls[$i+1]) ) { $ch = curl_init(); $options[CURLOPT_URL] = $urls[$i+1]; ++$i; // increment i curl_setopt_array($ch,$options); curl_multi_add_handle($master, $ch); curl_multi_remove_handle($master, $done['handle']); } // remove the curl handle that just completed else curl_multi_remove_handle($master, $done['handle']); } } } while ($running); curl_multi_close($master); return true; } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 11, Position 2 = 2
Branch analysis from position: 11
Branch analysis from position: 2
filename:       /in/Res4D
function name:  (null)
number of ops:  35
compiled vars:  !0 = $i, !1 = $urls, !2 = $start, !3 = $thr, !4 = $end, !5 = $time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 0
          1      > JMP                                                      ->9
    4     2    >   CONCAT                                           ~8      'http%3A%2F%2Fwww.goo598541e', !0
          3        CONCAT                                           ~9      ~8, '.com%2Fsearch%3Fq%3D'
          4        CONCAT                                           ~10     ~9, !0
          5        CONCAT                                           ~11     ~10, 'ab'
          6        ASSIGN_DIM                                               !1
          7        OP_DATA                                                  ~11
    2     8        PRE_INC                                                  !0
          9    >   IS_SMALLER_OR_EQUAL                                      !0, 100
         10      > JMPNZ                                                    ~13, ->2
   10    11    >   INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $14     
         14        ASSIGN                                                   !2, $14
   13    15        INIT_FCALL_BY_NAME                                       'rolling_curl'
         16        SEND_VAR_EX                                              !1
         17        SEND_VAR_EX                                              !3
         18        SEND_VAL_EX                                              'cb'
         19        DO_FCALL                                      0          
   15    20        INIT_FCALL                                               'microtime'
         21        SEND_VAL                                                 <true>
         22        DO_ICALL                                         $17     
         23        ASSIGN                                                   !4, $17
   16    24        SUB                                              ~19     !4, !2
         25        ASSIGN                                                   !5, ~19
   17    26        INIT_FCALL                                               'round'
         27        SEND_VAR                                                 !5
         28        SEND_VAL                                                 2
         29        DO_ICALL                                         $21     
         30        CONCAT                                           ~22     '%3Cb%3ETotal+time+', $21
         31        CONCAT                                           ~23     ~22, '+seconds%3C%2Fb%3E%3Cbr+%2F%3E'
         32        CONCAT                                           ~24     ~23, '%0A'
         33        ECHO                                                     ~24
   98    34      > RETURN                                                   1

Function rolling_curl:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 35
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 54
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 66
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 172
Branch analysis from position: 172
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 166
Branch analysis from position: 166
2 jumps found. (Code = 44) Position 1 = 171, Position 2 = 67
Branch analysis from position: 171
2 jumps found. (Code = 44) Position 1 = 172, Position 2 = 53
Branch analysis from position: 172
Branch analysis from position: 53
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 123
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 92, Position 2 = 116
Branch analysis from position: 92
1 jumps found. (Code = 42) Position 1 = 122
Branch analysis from position: 122
1 jumps found. (Code = 42) Position 1 = 166
Branch analysis from position: 166
Branch analysis from position: 116
1 jumps found. (Code = 42) Position 1 = 166
Branch analysis from position: 166
Branch analysis from position: 123
2 jumps found. (Code = 43) Position 1 = 136, Position 2 = 160
Branch analysis from position: 136
1 jumps found. (Code = 42) Position 1 = 166
Branch analysis from position: 166
Branch analysis from position: 160
2 jumps found. (Code = 44) Position 1 = 171, Position 2 = 67
Branch analysis from position: 171
Branch analysis from position: 67
Branch analysis from position: 54
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 35
Branch analysis from position: 53
Branch analysis from position: 35
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
Branch analysis from position: 31
filename:       /in/Res4D
function name:  rolling_curl
number of ops:  177
compiled vars:  !0 = $urls, !1 = $rolling_window, !2 = $callback, !3 = $custom_options, !4 = $master, !5 = $curl_arr, !6 = $std_options, !7 = $options, !8 = $i, !9 = $ch, !10 = $execrun, !11 = $running, !12 = $info, !13 = $done, !14 = $output, !15 = $start
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      null
   23     4        COUNT                                            ~16     !0
          5        IS_SMALLER                                               ~16, !1
          6      > JMPZ                                                     ~17, ->10
          7    >   COUNT                                            ~18     !0
          8        QM_ASSIGN                                        ~19     ~18
          9      > JMP                                                      ->11
         10    >   QM_ASSIGN                                        ~19     !1
         11    >   ASSIGN                                                   !1, ~19
   26    12        INIT_FCALL_BY_NAME                                       'curl_multi_init'
         13        DO_FCALL                                      0  $21     
         14        ASSIGN                                                   !4, $21
   27    15        ASSIGN                                                   !5, <array>
   31    16        FETCH_CONSTANT                                   ~24     'CURLOPT_RETURNTRANSFER'
         17        INIT_ARRAY                                       ~25     <true>, ~24
   33    18        FETCH_CONSTANT                                   ~26     'CURLOPT_CONNECTTIMEOUT_MS'
         19        ADD_ARRAY_ELEMENT                                ~25     2000, ~26
   34    20        FETCH_CONSTANT                                   ~27     'CURLOPT_TIMEOUT_MS'
         21        ADD_ARRAY_ELEMENT                                ~25     2000, ~27
   35    22        FETCH_CONSTANT                                   ~28     'CURLOPT_FRESH_CONNECT'
   31    23        ADD_ARRAY_ELEMENT                                ~25     <true>, ~28
   36    24        FETCH_CONSTANT                                   ~29     'CURLOPT_FORBID_REUSE'
   31    25        ADD_ARRAY_ELEMENT                                ~25     <true>, ~29
   30    26        ASSIGN                                                   !6, ~25
   38    27      > JMPZ                                                     !3, ->31
         28    >   ADD                                              ~31     !6, !3
         29        QM_ASSIGN                                        ~32     ~31
         30      > JMP                                                      ->32
         31    >   QM_ASSIGN                                        ~32     !6
         32    >   ASSIGN                                                   !7, ~32
   41    33        ASSIGN                                                   !8, 0
         34      > JMP                                                      ->51
   42    35    >   INIT_FCALL_BY_NAME                                       'curl_init'
         36        DO_FCALL                                      0  $35     
         37        ASSIGN                                                   !9, $35
   43    38        FETCH_CONSTANT                                   ~37     'CURLOPT_URL'
         39        FETCH_DIM_R                                      ~39     !0, !8
         40        ASSIGN_DIM                                               !7, ~37
         41        OP_DATA                                                  ~39
   44    42        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
         43        SEND_VAR_EX                                              !9
         44        SEND_VAR_EX                                              !7
         45        DO_FCALL                                      0          
   45    46        INIT_FCALL_BY_NAME                                       'curl_multi_add_handle'
         47        SEND_VAR_EX                                              !4
         48        SEND_VAR_EX                                              !9
         49        DO_FCALL                                      0          
   41    50        PRE_INC                                                  !8
         51    >   IS_SMALLER                                               !8, !1
         52      > JMPNZ                                                    ~43, ->35
   49    53    > > JMP                                                      ->54
         54    >   INIT_FCALL_BY_NAME                                       'curl_multi_exec'
         55        SEND_VAR_EX                                              !4
         56        SEND_VAR_EX                                              !11
         57        DO_FCALL                                      0  $44     
         58        ASSIGN                                           ~45     !10, $44
         59        FETCH_CONSTANT                                   ~46     'CURLM_CALL_MULTI_PERFORM'
         60        IS_EQUAL                                                 ~45, ~46
         61      > JMPNZ                                                    ~47, ->54
   51    62    >   FETCH_CONSTANT                                   ~48     'CURLM_OK'
         63        IS_NOT_EQUAL                                             !10, ~48
         64      > JMPZ                                                     ~49, ->66
   52    65    > > JMP                                                      ->172
   54    66    > > JMP                                                      ->166
   55    67    >   INIT_FCALL_BY_NAME                                       'curl_getinfo'
         68        CHECK_FUNC_ARG                                           
         69        FETCH_DIM_FUNC_ARG                               $50     !13, 'handle'
         70        SEND_FUNC_ARG                                            $50
         71        DO_FCALL                                      0  $51     
         72        ASSIGN                                                   !12, $51
   56    73        FETCH_DIM_R                                      ~53     !12, 'http_code'
         74        IS_EQUAL                                                 ~53, 200
         75      > JMPZ                                                     ~54, ->123
   57    76    >   INIT_FCALL_BY_NAME                                       'curl_multi_getcontent'
         77        CHECK_FUNC_ARG                                           
         78        FETCH_DIM_FUNC_ARG                               $55     !13, 'handle'
         79        SEND_FUNC_ARG                                            $55
         80        DO_FCALL                                      0  $56     
         81        ASSIGN                                                   !14, $56
   60    82        INIT_DYNAMIC_CALL                                        !2
         83        SEND_VAR_EX                                              !14
         84        CHECK_FUNC_ARG                                           
         85        FETCH_DIM_FUNC_ARG                               $58     !12, 'url'
         86        SEND_FUNC_ARG                                            $58
         87        SEND_VAR_EX                                              !15
         88        DO_FCALL                                      0          
   63    89        ADD                                              ~60     !8, 1
         90        ISSET_ISEMPTY_DIM_OBJ                         0          !0, ~60
         91      > JMPZ                                                     ~61, ->116
   64    92    >   INIT_FCALL_BY_NAME                                       'curl_init'
         93        DO_FCALL                                      0  $62     
         94        ASSIGN                                                   !9, $62
   65    95        FETCH_CONSTANT                                   ~64     'CURLOPT_URL'
         96        ADD                                              ~66     !8, 1
         97        FETCH_DIM_R                                      ~67     !0, ~66
         98        ASSIGN_DIM                                               !7, ~64
         99        OP_DATA                                                  ~67
        100        PRE_INC                                                  !8
   66   101        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
        102        SEND_VAR_EX                                              !9
        103        SEND_VAR_EX                                              !7
        104        DO_FCALL                                      0          
   67   105        INIT_FCALL_BY_NAME                                       'curl_multi_add_handle'
        106        SEND_VAR_EX                                              !4
        107        SEND_VAR_EX                                              !9
        108        DO_FCALL                                      0          
   70   109        INIT_FCALL_BY_NAME                                       'curl_multi_remove_handle'
        110        SEND_VAR_EX                                              !4
        111        CHECK_FUNC_ARG                                           
        112        FETCH_DIM_FUNC_ARG                               $71     !13, 'handle'
        113        SEND_FUNC_ARG                                            $71
        114        DO_FCALL                                      0          
        115      > JMP                                                      ->122
   72   116    >   INIT_FCALL_BY_NAME                                       'curl_multi_remove_handle'
        117        SEND_VAR_EX                                              !4
        118        CHECK_FUNC_ARG                                           
        119        FETCH_DIM_FUNC_ARG                               $73     !13, 'handle'
        120        SEND_FUNC_ARG                                            $73
        121        DO_FCALL                                      0          
        122    > > JMP                                                      ->166
   75   123    >   INIT_FCALL_BY_NAME                                       'curl_error'
        124        CHECK_FUNC_ARG                                           
        125        FETCH_DIM_FUNC_ARG                               $75     !13, 'handle'
        126        SEND_FUNC_ARG                                            $75
        127        DO_FCALL                                      0  $76     
        128        CONCAT                                           ~77     $76, '+-+'
        129        FETCH_DIM_R                                      ~78     !12, 'url'
        130        CONCAT                                           ~79     ~77, ~78
        131        CONCAT                                           ~80     ~79, '+%3Cbr%2F%3E%0A%0D'
        132        ECHO                                                     ~80
   79   133        ADD                                              ~81     !8, 1
        134        ISSET_ISEMPTY_DIM_OBJ                         0          !0, ~81
        135      > JMPZ                                                     ~82, ->160
   80   136    >   INIT_FCALL_BY_NAME                                       'curl_init'
        137        DO_FCALL                                      0  $83     
        138        ASSIGN                                                   !9, $83
   81   139        FETCH_CONSTANT                                   ~85     'CURLOPT_URL'
        140        ADD                                              ~87     !8, 1
        141        FETCH_DIM_R                                      ~88     !0, ~87
        142        ASSIGN_DIM                                               !7, ~85
        143        OP_DATA                                                  ~88
        144        PRE_INC                                                  !8
   82   145        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
        146        SEND_VAR_EX                                              !9
        147        SEND_VAR_EX                                              !7
        148        DO_FCALL                                      0          
   83   149        INIT_FCALL_BY_NAME                                       'curl_multi_add_handle'
        150        SEND_VAR_EX                                              !4
        151        SEND_VAR_EX                                              !9
        152        DO_FCALL                                      0          
   84   153        INIT_FCALL_BY_NAME                                       'curl_multi_remove_handle'
        154        SEND_VAR_EX                                              !4
        155        CHECK_FUNC_ARG                                           
        156        FETCH_DIM_FUNC_ARG                               $92     !13, 'handle'
        157        SEND_FUNC_ARG                                            $92
        158        DO_FCALL                                      0          
        159      > JMP                                                      ->166
   89   160    >   INIT_FCALL_BY_NAME                                       'curl_multi_remove_handle'
        161        SEND_VAR_EX                                              !4
        162        CHECK_FUNC_ARG                                           
        163        FETCH_DIM_FUNC_ARG                               $94     !13, 'handle'
        164        SEND_FUNC_ARG                                            $94
        165        DO_FCALL                                      0          
   54   166    >   INIT_FCALL_BY_NAME                                       'curl_multi_info_read'
        167        SEND_VAR_EX                                              !4
        168        DO_FCALL                                      0  $96     
        169        ASSIGN                                           ~97     !13, $96
        170      > JMPNZ                                                    ~97, ->67
   92   171    > > JMPNZ                                                    !11, ->53
   94   172    >   INIT_FCALL_BY_NAME                                       'curl_multi_close'
        173        SEND_VAR_EX                                              !4
        174        DO_FCALL                                      0          
   95   175      > RETURN                                                   <true>
   96   176*     > RETURN                                                   null

End of function rolling_curl

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
258.61 ms | 1416 KiB | 18 Q