在后台运行一个进程,没有延迟php应用程序

时间:2014-03-18 14:03:06

标签: php post curl http-post http-status-code-404

是php开发的新手

我发送curl php帖子到外部网址,我想检查帖子的统计数据是否不等于200应用程序应该在15分钟后发送相同的帖子和相同的数据,我这样做,它的工作非常好,但我的问题是我使用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));
?>
谢谢大家 最诚挚的问候

1 个答案:

答案 0 :(得分:0)

嗯,您可以使用&#34; ignore_user_abort(true)&#34;

因此脚本将继续工作(密切关注脚本持续时间,或许添加&#34; set_time_limit(0)&#34;)

但是这里有一个警告:你将无法使用这两行停止脚本:

ignore_user_abort(true); 
set_time_limit(0);

除了你可以直接访问服务器并杀死那里的进程! (在那里,做了一个无休止的循环,一遍又一遍地呼唤自己,让服务器突然停下来,大声喊叫......)

Also this url may help