我是PHP开发新手
我发送curl PHP post到外部url,我想检查post的统计信息是否不等于200 PHP应用程序应该在15分钟后发送相同的post和相同的数据,我这样做,它工作得很好,但我的问题是我使用sleep();函数将帖子延迟15分钟,并且我的应用程序正在忙,直到睡眠函数结束,我想问一下我是否可以在后台执行此案例而不会延迟应用程序。
这是我的代码:
<?php
$command = $Curl_Session = curl_init('http:www.example.com');
$command .= curl_setopt ($Curl_Session, CURLOPT_POST, 1);
$command .= curl_setopt ($Curl_Session, CURLOPT_POSTFIELDS, "contentID=".$newsId."&contentType=".$content_type."&contentTitle=".$newsTitle."&contentBody=".urlencode(wordwrap($newsBody,true))."&contentOfToday=".$news_today."&contentTime=".$date_created."&contentIMGURL=".$news_image."&contentURL=".$bath_to_share."");
$command .= curl_setopt ($Curl_Session, CURLOPT_FOLLOWLOCATION, 1);
$command .= curl_exec ($Curl_Session);
sleep(10000);
shell_exec(sprintf('%s > /dev/null 2>&1 &', $command));
?>
谢谢大家问候
你可以使用"ignore_user_abort(true) "
所以脚本将继续工作(注意脚本持续时间,也许添加"set_time_limit(0)")
但是这里有一个警告:你不能用这两行来停止脚本:
ignore_user_abort(true);
set_time_limit(0);
除非你可以直接访问服务器并在那里杀死进程!(在那里,做了一个无尽的循环,一遍又一遍地调用自己,使服务器戛然停止,被大喊大叫…)