Last active
March 27, 2017 03:54
-
-
Save lgh06/2a334b4b4ba0432a8a25fb533e391e97 to your computer and use it in GitHub Desktop.
This file contains 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 | |
//phpinfo(); | |
// render basic ttkk-share page's DOM. | |
$vid = $_GET["vid"]; | |
//multi curl resource | |
$re = array(); // 暂存curl函数返回的资源 | |
$html = array(); //数组,暂存远程接口返回的数据 | |
function Request($url) | |
{ | |
$curl = curl_init(); | |
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,FALSE);//禁用后cURL将终止从服务端进行验证。使用CURLOPT_CAINFO选项设置证书使用CURLOPT_CAPATH选项设置证书目录 如果CURLOPT_SSL_VERIFYPEER(默认值为2)被启用,CURLOPT_SSL_VERIFYHOST需要被设置成TRUE否则设置为FALSE。 | |
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); | |
curl_setopt($curl, CURLOPT_HTTPGET, TRUE);//默认即为GET请求 | |
curl_setopt($curl, CURLOPT_TIMEOUT, 3);//允许 cURL 函数执行的最长秒数 | |
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);//在尝试连接时等待的秒数。设置为0,则无限等待。 | |
curl_setopt($curl, CURLOPT_DNS_CACHE_TIMEOUT, 600);//设置在内存中缓存 DNS 的时间,默认为120秒(两分钟)。 | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//将exec执行结果以文件流形式返回不是直接输出到浏览器 | |
curl_setopt($curl, CURLOPT_URL, $url);//需要获取的URL地址,也可以在curl_init()函数中设置。 | |
global $re; | |
array_push($re, $curl); | |
return $curl; | |
} | |
$mh = curl_multi_init(); | |
curl_multi_add_handle($mh, Request('http://srv.ttkk.kankan.com/api/v1/video?video_id=' . $vid)); | |
curl_multi_add_handle($mh, Request('http://srv.ttkk.kankan.com/api/v1/video/related_video?video_id=' . $vid)); | |
// 执行批处理句柄 | |
// http://cn2.php.net/manual/zh/function.curl-multi-exec.php | |
do { | |
curl_multi_exec($mh, $running); | |
curl_multi_select($mh); | |
} while ($running > 0); | |
foreach ($re as $k=>$ch) { | |
$resp = curl_multi_getcontent($ch); // get the content | |
array_push($html, $resp); | |
// do what you want with the HTML | |
curl_multi_remove_handle($mh, $ch); // remove the handle (assuming you are done with it); | |
} | |
// 关闭全部句柄 | |
curl_multi_close($mh); | |
// TODO 处理数据 | |
print_r($html); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment