Created
February 28, 2020 18:57
-
-
Save Toxiapo/747b7150731f42e007631df8a8efa4cc to your computer and use it in GitHub Desktop.
mult-contnet-with-curl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getMultiContents($url_list) | |
{ | |
$mh = curl_multi_init(); | |
$ch_list = array(); | |
foreach ($url_list as $url) { | |
$ch_list[$url] = curl_init($url); | |
curl_setopt($ch_list[$url], CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch_list[$url], CURLOPT_TIMEOUT, 1); | |
curl_setopt($ch_list[$url], CURLOPT_SSL_VERIFYPEER, false); | |
curl_multi_add_handle($mh, $ch_list[$url]); | |
} | |
$running = null; | |
do { | |
curl_multi_exec($mh, $running); | |
} while ($running); | |
foreach ($url_list as $url) { | |
$results[$url] = curl_getinfo($ch_list[$url]); | |
$results[$url]["content"] = curl_multi_getcontent($ch_list[$url]); | |
curl_multi_remove_handle($mh, $ch_list[$url]); | |
curl_close($ch_list[$url]); | |
} | |
curl_multi_close($mh); | |
return $results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment