3v4l.org

run code in 300+ PHP versions simultaneously
<?php $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 = 62) Position 1 = -2
filename:       /in/ba521
function name:  (null)
number of ops:  24
compiled vars:  !0 = $start, !1 = $urls, !2 = $thr, !3 = $end, !4 = $time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'microtime'
          1        SEND_VAL                                                 <true>
          2        DO_ICALL                                         $5      
          3        ASSIGN                                                   !0, $5
    6     4        INIT_FCALL_BY_NAME                                       'rolling_curl'
          5        SEND_VAR_EX                                              !1
          6        SEND_VAR_EX                                              !2
          7        SEND_VAL_EX                                              'cb'
          8        DO_FCALL                                      0          
    8     9        INIT_FCALL                                               'microtime'
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $8      
         12        ASSIGN                                                   !3, $8
    9    13        SUB                                              ~10     !3, !0
         14        ASSIGN                                                   !4, ~10
   10    15        INIT_FCALL                                               'round'
         16        SEND_VAR                                                 !4
         17        SEND_VAL                                                 2
         18        DO_ICALL                                         $12     
         19        CONCAT                                           ~13     '%3Cb%3ETotal+time+', $12
         20        CONCAT                                           ~14     ~13, '+seconds%3C%2Fb%3E%3Cbr+%2F%3E'
         21        CONCAT                                           ~15     ~14, '%0A'
         22        ECHO                                                     ~15
   91    23      > 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/ba521
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
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      null
   16     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
   19    12        INIT_FCALL_BY_NAME                                       'curl_multi_init'
         13        DO_FCALL                                      0  $21     
         14        ASSIGN                                                   !4, $21
   20    15        ASSIGN                                                   !5, <array>
   24    16        FETCH_CONSTANT                                   ~24     'CURLOPT_RETURNTRANSFER'
         17        INIT_ARRAY                                       ~25     <true>, ~24
   26    18        FETCH_CONSTANT                                   ~26     'CURLOPT_CONNECTTIMEOUT_MS'
         19        ADD_ARRAY_ELEMENT                                ~25     2000, ~26
   27    20        FETCH_CONSTANT                                   ~27     'CURLOPT_TIMEOUT_MS'
         21        ADD_ARRAY_ELEMENT                                ~25     2000, ~27
   28    22        FETCH_CONSTANT                                   ~28     'CURLOPT_FRESH_CONNECT'
   24    23        ADD_ARRAY_ELEMENT                                ~25     <true>, ~28
   29    24        FETCH_CONSTANT                                   ~29     'CURLOPT_FORBID_REUSE'
   24    25        ADD_ARRAY_ELEMENT                                ~25     <true>, ~29
   23    26        ASSIGN                                                   !6, ~25
   31    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
   34    33        ASSIGN                                                   !8, 0
         34      > JMP                                                      ->51
   35    35    >   INIT_FCALL_BY_NAME                                       'curl_init'
         36        DO_FCALL                                      0  $35     
         37        ASSIGN                                                   !9, $35
   36    38        FETCH_CONSTANT                                   ~37     'CURLOPT_URL'
         39        FETCH_DIM_R                                      ~39     !0, !8
         40        ASSIGN_DIM                                               !7, ~37
         41        OP_DATA                                                  ~39
   37    42        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
         43        SEND_VAR_EX                                              !9
         44        SEND_VAR_EX                                              !7
         45        DO_FCALL                                      0          
   38    46        INIT_FCALL_BY_NAME                                       'curl_multi_add_handle'
         47        SEND_VAR_EX                                              !4
         48        SEND_VAR_EX                                              !9
         49        DO_FCALL                                      0          
   34    50        PRE_INC                                                  !8
         51    >   IS_SMALLER                                               !8, !1
         52      > JMPNZ                                                    ~43, ->35
   42    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
   44    62    >   FETCH_CONSTANT                                   ~48     'CURLM_OK'
         63        IS_NOT_EQUAL                                             !10, ~48
         64      > JMPZ                                                     ~49, ->66
   45    65    > > JMP                                                      ->172
   47    66    > > JMP                                                      ->166
   48    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
   49    73        FETCH_DIM_R                                      ~53     !12, 'http_code'
         74        IS_EQUAL                                                 ~53, 200
         75      > JMPZ                                                     ~54, ->123
   50    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
   53    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          
   56    89        ADD                                              ~60     !8, 1
         90        ISSET_ISEMPTY_DIM_OBJ                         0          !0, ~60
         91      > JMPZ                                                     ~61, ->116
   57    92    >   INIT_FCALL_BY_NAME                                       'curl_init'
         93        DO_FCALL                                      0  $62     
         94        ASSIGN                                                   !9, $62
   58    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
   59   101        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
        102        SEND_VAR_EX                                              !9
        103        SEND_VAR_EX                                              !7
        104        DO_FCALL                                      0          
   60   105        INIT_FCALL_BY_NAME                                       'curl_multi_add_handle'
        106        SEND_VAR_EX                                              !4
        107        SEND_VAR_EX                                              !9
        108        DO_FCALL                                      0          
   63   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
   65   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
   68   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
   72   133        ADD                                              ~81     !8, 1
        134        ISSET_ISEMPTY_DIM_OBJ                         0          !0, ~81
        135      > JMPZ                                                     ~82, ->160
   73   136    >   INIT_FCALL_BY_NAME                                       'curl_init'
        137        DO_FCALL                                      0  $83     
        138        ASSIGN                                                   !9, $83
   74   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
   75   145        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
        146        SEND_VAR_EX                                              !9
        147        SEND_VAR_EX                                              !7
        148        DO_FCALL                                      0          
   76   149        INIT_FCALL_BY_NAME                                       'curl_multi_add_handle'
        150        SEND_VAR_EX                                              !4
        151        SEND_VAR_EX                                              !9
        152        DO_FCALL                                      0          
   77   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
   82   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          
   47   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
   85   171    > > JMPNZ                                                    !11, ->53
   87   172    >   INIT_FCALL_BY_NAME                                       'curl_multi_close'
        173        SEND_VAR_EX                                              !4
        174        DO_FCALL                                      0          
   88   175      > RETURN                                                   <true>
   89   176*     > RETURN                                                   null

End of function rolling_curl

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.98 ms | 1416 KiB | 17 Q