您好,欢迎访问一九零五行业门户网

错误500 ;End of script output before headers: index.php

thinkphp框架,用curl爬取某网站用ajax生成的分页数据,脚本最大执行时间设置为0.运行脚本一段时间后浏览器显示错误500: ,apache错误日志报错:end of script output before headers: index.php。 代码如下:
public function multi(){ $page = 128;//ajax的分页数 $max_size = 10;//并发数 //url数组 $url_arr = array(); //生成url数组 for($i = 1;$i <= $page; $i++){ $url = 'http://www.wdzj.com/front_select-plat?params=&sort=0&currpage='; $url .= $i; $url_arr[] = $url; } $mh = curl_multi_init(); //每次只放出$max_size大小的url用来初始化 $count = count($url_arr); for($i=0;$i<$count;$i++){ $ch = curl_init(); curl_setopt($ch, curlopt_url, $url_arr[$i]); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_timeout, 5); curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows nt 6.1; wow64) applewebkit/537.36 (khtml, like gecko) chrome/44.0.2403.130 safari/537.36'); curl_setopt($ch, curlopt_returntransfer, true); curl_multi_add_handle($mh, $ch); $requestmap[] = $ch; if(count($requestmap)<$max_size && ++$i != $count) continue;//保证数组中每次有$max_size个请求且请求的url还没有用完 $active = null; //执行批处理句柄 do{ $mrc = curl_multi_exec($mh, $active); }while($mrc == curlm_call_multi_perform); while($active && $mrc == curlm_ok){ if(curl_multi_select($mh) != -1){ do{ $mrc = curl_multi_exec($mh, $active); }while($mrc == curlm_call_multi_perform); } } $json_arr = array();//存放ajax返回的接口数据 //获取资源并且关闭句柄 foreach($requestmap as $ch){ $json_arr[] = curl_multi_getcontent($ch);// file_put_contents($i.'.txt', $json); $error = curl_error($ch); if($error != '') exit('发生了错误:'.$error); curl_multi_remove_handle($mh, $ch); } unset($requestmap); } curl_multi_close($mh); file_put_contents('1.txt', json_encode($json_arr)); }
回复讨论(解决方案) 打开 php 的错误显示,500 多半是被错误信息憋死的
从代码上看,最大的可能是内存不足
你好,平常没有怎么去接触错误显示的设置。 照网上设置,重启apache后。再执行,还是那种错误。我附上apache的完整点的错误日志吧,不过自己看不明白。
[thu may 05 17:08:52.673028 2016] [core:warn] [pid 20268:tid 320] ah00098: pid file d:/phpstudy/apache/logs/httpd.pid overwritten -- unclean shutdown of previous apache run?[thu may 05 17:08:52.811036 2016] [mpm_winnt:notice] [pid 20268:tid 320] ah00455: apache/2.4.10 (win32) openssl/1.0.1i mod_fcgid/2.3.9 configured -- resuming normal operations[thu may 05 17:08:52.811036 2016] [mpm_winnt:notice] [pid 20268:tid 320] ah00456: apache lounge vc9 server built: jul 19 2014 13:20:51[thu may 05 17:08:52.811036 2016] [core:notice] [pid 20268:tid 320] ah00094: command line: 'd:\\phpstudy\\apache\\bin\\httpd.exe -d d:/phpstudy/apache'[thu may 05 17:08:52.814036 2016] [mpm_winnt:notice] [pid 20268:tid 320] ah00418: parent: created child process 21132[thu may 05 17:08:54.476131 2016] [mpm_winnt:notice] [pid 21132:tid 336] ah00354: child: starting 150 worker threads.[thu may 05 17:15:20.696222 2016] [core:error] [pid 21132:tid 1724] [client 127.0.0.1:60080] end of script output before headers: index.php
从代码上看,最大的可能是内存不足
我也一直在看运行过程中的内存,一直没有超过百分之八十
从代码上看,最大的可能是内存不足
我也一直在看运行过程中的内存,一直没有超过百分之八十
我再改下代码吧
系统内存 和 php 可用内存 不是一个概念
你就是个 500,神仙也不知道是怎么回事
php.ini 中令display_errors=on 打开错误提示功能再说吧
开启错误提示

系统内存 和 php 可用内存 不是一个概念
你就是个 500,神仙也不知道是怎么回事
额,是curl_multi_select()函数的问题,删掉那部分就可以了,不过照着参考文档上写的,都有问题,这我就不明白了。内存的不足的问题是在后面出现了,也解决了。多谢额。结贴
其它类似信息

推荐信息