3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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, 10 , "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; } ?>
based on Res4D
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function curl_multi_init() in /in/jNXMV:26 Stack trace: #0 /in/jNXMV(13): rolling_curl(Array, 10, 'cb') #1 {main} thrown in /in/jNXMV on line 26
Process exited with code 255.
Output for hhvm-3.12.0
Could not resolve host: www.goo598541e2.com - http://www.goo598541e2.com/search?q=2ab <br/> Could not resolve host: www.goo598541e3.com - http://www.goo598541e3.com/search?q=3ab <br/> Could not resolve host: www.goo598541e5.com - http://www.goo598541e5.com/search?q=5ab <br/> Could not resolve host: www.goo598541e0.com - http://www.goo598541e0.com/search?q=0ab <br/> Could not resolve host: www.goo598541e1.com - http://www.goo598541e1.com/search?q=1ab <br/> Could not resolve host: www.goo598541e4.com - http://www.goo598541e4.com/search?q=4ab <br/> Could not resolve host: www.goo598541e6.com - http://www.goo598541e6.com/search?q=6ab <br/> Could not resolve host: www.goo598541e8.com - http://www.goo598541e8.com/search?q=8ab <br/> Could not resolve host: www.goo598541e7.com - http://www.goo598541e7.com/search?q=7ab <br/> Could not resolve host: www.goo598541e9.com - http://www.goo598541e9.com/search?q=9ab <br/> Could not resolve host: www.goo598541e11.com - http://www.goo598541e11.com/search?q=11ab <br/> Could not resolve host: www.goo598541e12.com - http://www.goo598541e12.com/search?q=12ab <br/> Could not resolve host: www.goo598541e14.com - http://www.goo598541e14.com/search?q=14ab <br/> Could not resolve host: www.goo598541e15.com - http://www.goo598541e15.com/search?q=15ab <br/> Could not resolve host: www.goo598541e16.com - http://www.goo598541e16.com/search?q=16ab <br/> Could not resolve host: www.goo598541e13.com - http://www.goo598541e13.com/search?q=13ab <br/> Could not resolve host: www.goo598541e17.com - http://www.goo598541e17.com/search?q=17ab <br/> Could not resolve host: www.goo598541e18.com - http://www.goo598541e18.com/search?q=18ab <br/> Could not resolve host: www.goo598541e22.com - http://www.goo598541e22.com/search?q=22ab <br/> Could not resolve host: www.goo598541e19.com - http://www.goo598541e19.com/search?q=19ab <br/> Could not resolve host: www.goo598541e20.com - http://www.goo598541e20.com/search?q=20ab <br/> Could not resolve host: www.goo598541e21.com - http://www.goo598541e21.com/search?q=21ab <br/> Could not resolve host: www.goo598541e26.com - http://www.goo598541e26.com/search?q=26ab <br/> Could not resolve host: www.goo598541e25.com - http://www.goo598541e25.com/search?q=25ab <br/> Could not resolve host: www.goo598541e23.com - http://www.goo598541e23.com/search?q=23ab <br/> Could not resolve host: www.goo598541e27.com - http://www.goo598541e27.com/search?q=27ab <br/> Could not resolve host: www.goo598541e24.com - http://www.goo598541e24.com/search?q=24ab <br/> Could not resolve host: www.goo598541e28.com - http://www.goo598541e28.com/search?q=28ab <br/> Could not resolve host: www.goo598541e29.com - http://www.goo598541e29.com/search?q=29ab <br/> Could not resolve host: www.goo598541e30.com - http://www.goo598541e30.com/search?q=30ab <br/> Could not resolve host: www.goo598541e31.com - http://www.goo598541e31.com/search?q=31ab <br/> Could not resolve host: www.goo598541e33.com - http://www.goo598541e33.com/search?q=33ab <br/> Could not resolve host: www.goo598541e32.com - http://www.goo598541e32.com/search?q=32ab <br/> Could not resolve host: www.goo598541e34.com - http://www.goo598541e34.com/search?q=34ab <br/> Could not resolve host: www.goo598541e35.com - http://www.goo598541e35.com/search?q=35ab <br/> Could not resolve host: www.goo598541e36.com - http://www.goo598541e36.com/search?q=36ab <br/> Could not resolve host: www.goo598541e38.com - http://www.goo598541e38.com/search?q=38ab <br/> Could not resolve host: www.goo598541e39.com - http://www.goo598541e39.com/search?q=39ab <br/> Could not resolve host: www.goo598541e40.com - http://www.goo598541e40.com/search?q=40ab <br/> Could not resolve host: www.goo598541e37.com - http://www.goo598541e37.com/search?q=37ab <br/> Could not resolve host: www.goo598541e41.com - http://www.goo598541e41.com/search?q=41ab <br/> Could not resolve host: www.goo598541e42.com - http://www.goo598541e42.com/search?q=42ab <br/> Could not resolve host: www.goo598541e50.com - http://www.goo598541e50.com/search?q=50ab <br/> Could not resolve host: www.goo598541e43.com - http://www.goo598541e43.com/search?q=43ab <br/> Could not resolve host: www.goo598541e49.com - http://www.goo598541e49.com/search?q=49ab <br/> Could not resolve host: www.goo598541e45.com - http://www.goo598541e45.com/search?q=45ab <br/> Could not resolve host: www.goo598541e47.com - http://www.goo598541e47.com/search?q=47ab <br/> Could not resolve host: www.goo598541e46.com - http://www.goo598541e46.com/search?q=46ab <br/> Could not resolve host: www.goo598541e48.com - http://www.goo598541e48.com/search?q=48ab <br/> Could not resolve host: www.goo598541e53.com - http://www.goo598541e53.com/search?q=53ab <br/> Could not resolve host: www.goo598541e54.com - http://www.goo598541e54.com/search?q=54ab <br/> Could not resolve host: www.goo598541e55.com - http://www.goo598541e55.com/search?q=55ab <br/> Could not resolve host: www.goo598541e44.com - http://www.goo598541e44.com/search?q=44ab <br/> Could not resolve host: www.goo598541e51.com - http://www.goo598541e51.com/search?q=51ab <br/> Could not resolve host: www.goo598541e52.com - http://www.goo598541e52.com/search?q=52ab <br/> Could not resolve host: www.goo598541e57.com - http://www.goo598541e57.com/search?q=57ab <br/> Could not resolve host: www.goo598541e56.com - http://www.goo598541e56.com/search?q=56ab <br/> Could not resolve host: www.goo598541e58.com - http://www.goo598541e58.com/search?q=58ab <br/> Could not resolve host: www.goo598541e59.com - http://www.goo598541e59.com/search?q=59ab <br/> Could not resolve host: www.goo598541e60.com - http://www.goo598541e60.com/search?q=60ab <br/> Could not resolve host: www.goo598541e61.com - http://www.goo598541e61.com/search?q=61ab <br/> Could not resolve host: www.goo598541e62.com - http://www.goo598541e62.com/search?q=62ab <br/> Could not resolve host: www.goo598541e63.com - http://www.goo598541e63.com/search?q=63ab <br/> Could not resolve host: www.goo598541e64.com - http://www.goo598541e64.com/search?q=64ab <br/> Could not resolve host: www.goo598541e65.com - http://www.goo598541e65.com/search?q=65ab <br/> Could not resolve host: www.goo598541e66.com - http://www.goo598541e66.com/search?q=66ab <br/> Could not resolve host: www.goo598541e67.com - http://www.goo598541e67.com/search?q=67ab <br/> Could not resolve host: www.goo598541e68.com - http://www.goo598541e68.com/search?q=68ab <br/> Could not resolve host: www.goo598541e69.com - http://www.goo598541e69.com/search?q=69ab <br/> Could not resolve host: www.goo598541e70.com - http://www.goo598541e70.com/search?q=70ab <br/> Could not resolve host: www.goo598541e71.com - http://www.goo598541e71.com/search?q=71ab <br/> Could not resolve host: www.goo598541e72.com - http://www.goo598541e72.com/search?q=72ab <br/> Could not resolve host: www.goo598541e73.com - http://www.goo598541e73.com/search?q=73ab <br/> Could not resolve host: www.goo598541e74.com - http://www.goo598541e74.com/search?q=74ab <br/> Could not resolve host: www.goo598541e75.com - http://www.goo598541e75.com/search?q=75ab <br/> Could not resolve host: www.goo598541e76.com - http://www.goo598541e76.com/search?q=76ab <br/> Could not resolve host: www.goo598541e77.com - http://www.goo598541e77.com/search?q=77ab <br/> Could not resolve host: www.goo598541e79.com - http://www.goo598541e79.com/search?q=79ab <br/> Could not resolve host: www.goo598541e78.com - http://www.goo598541e78.com/search?q=78ab <br/> Could not resolve host: www.goo598541e81.com - http://www.goo598541e81.com/search?q=81ab <br/> Could not resolve host: www.goo598541e80.com - http://www.goo598541e80.com/search?q=80ab <br/> Could not resolve host: www.goo598541e82.com - http://www.goo598541e82.com/search?q=82ab <br/> Could not resolve host: www.goo598541e83.com - http://www.goo598541e83.com/search?q=83ab <br/> Could not resolve host: www.goo598541e84.com - http://www.goo598541e84.com/search?q=84ab <br/> Could not resolve host: www.goo598541e85.com - http://www.goo598541e85.com/search?q=85ab <br/> Could not resolve host: www.goo598541e86.com - http://www.goo598541e86.com/search?q=86ab <br/> Could not resolve host: www.goo598541e87.com - http://www.goo598541e87.com/search?q=87ab <br/> Could not resolve host: www.goo598541e88.com - http://www.goo598541e88.com/search?q=88ab <br/> Could not resolve host: www.goo598541e89.com - http://www.goo598541e89.com/search?q=89ab <br/> Could not resolve host: www.goo598541e90.com - http://www.goo598541e90.com/search?q=90ab <br/> Could not resolve host: www.goo598541e91.com - http://www.goo598541e91.com/search?q=91ab <br/> Could not resolve host: www.goo598541e92.com - http://www.goo598541e92.com/search?q=92ab <br/> Could not resolve host: www.goo598541e93.com - http://www.goo598541e93.com/search?q=93ab <br/> Could not resolve host: www.goo598541e94.com - http://www.goo598541e94.com/search?q=94ab <br/> Could not resolve host: www.goo598541e97.com - http://www.goo598541e97.com/search?q=97ab <br/> Could not resolve host: www.goo598541e95.com - http://www.goo598541e95.com/search?q=95ab <br/> Could not resolve host: www.goo598541e96.com - http://www.goo598541e96.com/search?q=96ab <br/> Could not resolve host: www.goo598541e98.com - http://www.goo598541e98.com/search?q=98ab <br/> Could not resolve host: www.goo598541e99.com - http://www.goo598541e99.com/search?q=99ab <br/> Could not resolve host: www.goo598541e100.com - http://www.goo598541e100.com/search?q=100ab <br/> <b>Total time 0.03 seconds</b><br />
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.0.0 - 5.6.28
Fatal error: Call to undefined function curl_multi_init() in /in/jNXMV on line 26
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: curl_multi_init() in /in/jNXMV on line 26
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: curl_multi_init() in /in/jNXMV on line 26
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: curl_multi_init() in /in/jNXMV on line 26