Skip to content

Instantly share code, notes, and snippets.

@Toxiapo
Created February 28, 2020 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Toxiapo/747b7150731f42e007631df8a8efa4cc to your computer and use it in GitHub Desktop.
Save Toxiapo/747b7150731f42e007631df8a8efa4cc to your computer and use it in GitHub Desktop.
mult-contnet-with-curl
<?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