lemeaco 大佬有话说 :
php大佬请进,问一个沙b问题( 解决了,我是沙B
本帖最后由 lemeaco 于 2020-12-8 18:13 编辑
https://s3.ax1x.com/2020/12/08/rpeRTx.png
https://s3.ax1x.com/2020/12/08/rpe201.png
url_list是一个包含下边几个数组的网址:https://netease-cloud-deepsea.glitch.me/
http://api-gearhost.rnm.plus/
https://netease-cloud.herokuapp.com/
然后foreach挨个去请求的时候,只有最后一个的状态码是200,其他的全是404,换个顺序还是这样,这是咋回事
解决了,我是沙B ,字符串里有空格https://cdn.jsdelivr.net/gh/hishis/forum-master/public/images/patch.gif
kieng 大佬有话说 :
本帖最后由 kieng 于 2020-12-8 17:51 编辑
建议用PHP的curl,别用file_get_contents这个函数.
function _curl($url, $post = false, $cookie = false, $timeout = 60) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // 最大执行时间
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode;
}
lemeaco 大佬有话说 :
kieng 大佬有话说 : 2020-12-8 17:48
建议用PHP的curl,别用file_get_contents这个函数.
这样也是只有最后一个的状态码是200,其他的都是0https://cdn.jsdelivr.net/gh/hishis/forum-master/public/images/patch.gif
teardrops 大佬有话说 :
不要用 foreach
你试试单个请求. 得到response 后 再请求下一个..
php貌似没有并发.. (想并发可以考虑python 或 go)
lanying 大佬有话说 :
你网站类型不同, https http的