3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php for($i=0;$i<=10000;++$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, 100 , "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 jNXMV
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function curl_multi_init() in /in/2NtOa:26 Stack trace: #0 /in/2NtOa(13): rolling_curl(Array, 100, 'cb') #1 {main} thrown in /in/2NtOa on line 26
Process exited with code 255.
Output for hhvm-3.12.0
Could not resolve host: www.google.com - http://www.google.com/search?q=0a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=1a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=2a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=3a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=4a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=5a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=6a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=7a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=8a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=9a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=10a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=11a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=12a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=13a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=14a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=15a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=16a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=17a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=18a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=19a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=20a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=21a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=22a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=23a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=24a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=25a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=26a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=27a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=28a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=29a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=30a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=31a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=32a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=33a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=34a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=35a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=36a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=37a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=38a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=39a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=40a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=41a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=42a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=43a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=44a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=45a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=46a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=47a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=48a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=49a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=50a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=51a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=52a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=53a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=54a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=55a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=56a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=57a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=58a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=59a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=60a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=61a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=62a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=63a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=64a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=65a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=66a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=67a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=68a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=69a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=70a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=71a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=72a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=73a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=74a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=75a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=76a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=77a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=78a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=79a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=80a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=81a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=82a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=83a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=84a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=85a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=86a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=87a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=88a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=89a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=90a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=91a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=92a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=93a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=94a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=95a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=96a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=97a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=98a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=99a&num=100 <br/> <b>Total time 0.04 seconds</b><br />
Output for hhvm-3.10.0
Could not resolve host: www.google.com - http://www.google.com/search?q=0a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=1a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=2a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=3a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=4a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=5a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=6a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=7a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=8a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=9a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=10a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=11a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=12a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=13a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=14a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=15a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=16a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=17a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=18a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=19a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=20a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=21a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=22a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=23a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=24a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=25a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=26a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=27a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=28a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=29a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=30a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=31a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=32a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=33a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=34a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=35a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=36a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=37a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=38a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=39a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=40a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=41a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=42a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=43a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=44a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=45a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=46a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=47a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=48a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=49a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=50a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=51a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=52a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=53a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=54a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=55a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=56a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=57a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=58a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=59a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=60a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=61a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=62a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=63a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=64a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=65a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=66a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=67a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=68a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=69a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=70a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=71a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=72a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=73a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=74a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=75a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=76a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=77a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=78a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=79a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=80a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=81a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=82a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=83a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=84a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=85a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=86a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=87a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=88a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=89a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=90a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=91a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=92a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=93a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=94a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=95a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=96a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=97a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=98a&num=100 <br/> Could not resolve host: www.google.com - http://www.google.com/search?q=99a&num=100 <br/> <b>Total time 0.05 seconds</b><br />
Output for 5.4.0 - 5.6.28
Fatal error: Call to undefined function curl_multi_init() in /in/2NtOa on line 26
Process exited with code 255.