$filename=dirname(dirname(__FILE__)).'./log/getreport.log';
$handle=fopen($filename,"a+");
while(!feof($handle)){$update_history=fgets($handle);}
if($update_history==NULL or $update_history==''){$update_history=date("Y-m-d",strtotime("-1 day"));}
$day=datediff('d',$update_history,date("Y-m-d"),false);
if($day>0){
if($filename==''){$filename=dirname(dirname(__FILE__)).'./log/getreport.log';}
file_put_contents($filename,date("Y-m-d"));
$fp = fsockopen('localhost',80,$errno,$errmsg);
fputs($fp, "GET /inc/cron.php\r\n\r\n");
fclose($fp);
}以上程序在本地测试时可以实现多线程,在不影响index.php运行的情况下,在服务器端就完成了cron.php,但是将程序上传到服务器后,发现cron.php根本就不运行了,这是怎么回事?怎么才能解决?
$handle=fopen($filename,"a+");
while(!feof($handle)){$update_history=fgets($handle);}
if($update_history==NULL or $update_history==''){$update_history=date("Y-m-d",strtotime("-1 day"));}
$day=datediff('d',$update_history,date("Y-m-d"),false);
if($day>0){
if($filename==''){$filename=dirname(dirname(__FILE__)).'./log/getreport.log';}
file_put_contents($filename,date("Y-m-d"));
$fp = fsockopen('localhost',80,$errno,$errmsg);
fputs($fp, "GET /inc/cron.php\r\n\r\n");
fclose($fp);
}以上程序在本地测试时可以实现多线程,在不影响index.php运行的情况下,在服务器端就完成了cron.php,但是将程序上传到服务器后,发现cron.php根本就不运行了,这是怎么回事?怎么才能解决?
————————————————————————————————
基于CSDN论坛提供的插件扩展功能,自己做了个签名档工具,分享给大家,欢迎技术交流 :)
还有这句 $fp = fsockopen('localhost',80,$errno,$errmsg);在服务器上你有权限写 localhost 的根目录吗?
把这个localhost换成你的http://www.xxx.com/目录文件名/, 看看,
首先,这个的确不叫多线程,只不过是在cron.php文件中使用了
ignore_user_abort(true);
set_time_limit(0);
来达到忽略前台用户中断,并无限时间运行的目的,当然,cron.php在完成操作后会有exit()退出自身。再次,localhost换成http://www.xxx.com/也是不运行,没有cron代码的问题,里面的开头记录一个LOG文件,LOG文件未创建,自然cron就未运行。最后,我记得PHP是不支持真正的多线程的,所以我用了这种方法来代替,而且本地测试良好,但到服务器上就是不行我用的是虚拟主机