2011-10-14 50 views
0

我编写了一个PHP脚本来使用APNS推送通知。我添加了一个PHP进度条来监视已经推送了多少用户。进度条显示在PHP页面中。我也不断更新一个MySOL数据库来记录这个数字。预计该脚本将运行很长时间。运行约3小时后,PHP页面(带进度条)停止,但是当我检查数据库时,推送的用户数量仍在增加。这意味着脚本仍在服务器内存中运行,但为什么页面显示停止?PHP脚本仍在服务器上运行,但网页显示已停止

这里是一些代码:

$count = 1; 
    while($row = mysql_fetch_array($result)) { 
     $pushToken = $row['pushToken']; 
     $result2 = mysql_query("SELECT COUNT(*) FROM deactivated_pushtokens WHERE pushToken LIKE '$pushToken'"); 
     list($token_deactivated) = mysql_fetch_row($result2); 

     if ($token_deactivated==0){ 
      if ($row['pushToken']!=""){ 
       if (strlen($row['pushToken']) == 64){//All valid push tokens will have a 32x2=64 length 
        //echo "<br>$count. Sending push to ".$row['deviceID']." Device token = ".$row['pushToken']; 
        //echo "<br><br>"; 

        if($count > $sendThreshold) 
        { 
         $pushMessage->sendMessage($row['pushToken'],$count,$appVersion,$mode,$message, $push_id); 
        } 



        if($count >= $push_update_count * $push_update_interval) 
        { 

         $pushlog_update = mysql_query("UPDATE pushlogs SET num_push_sent = '".$count."' WHERE push_id = '".$push_id."'"); 

         if(!$pushlog_update) 
         { 
//       echo "pushlog table update error: ".mysql_error."<br />"; 
         } 

/*      if($count<=$maxBar) // if failed again commment out and use block bleow 
         { 
          $prb->moveStep($count); 
         } 
*/      
         $push_update_count++; 

        } 

        if($count >= $update_progressbar_count * $update_progressbar_interval) 
        { 
         if($count<=$maxBar) 
         { 
          $prb->moveStep($count); 
         } 

         $update_progressbar_interval++; 
        } 

        $count++; 

        // move the Bar 
+0

你能显示一些代码吗? – someone

回答

1

也许页面显示在httpd.conf停止由于配置Apache

KeepAliveTimeout 300 

PHP仍然在运行,由于在php.ini中的财产的max_execution_time

+0

嗨,我检查了httpd.conf。没有KeepAliveTimeout。你的意思是我应该添加这一行吗?谢谢 – user955461

+0

顺便说一下,我用“set_time_limit(600)”将php max_execution_time设置为10分钟。到目前为止,php脚本运行了3个多小时,所以我想max_execution_time与脚本仍在运行无关。谢谢 – user955461

+0

BTW脚本在4小时后终止 – user955461

0

只是要注意,您根本不会调用mysql_error函数,而是替换行:

echo "pushlog table update error: ".mysql_error."
";

这一个:

echo "pushlog table update error: ".mysql_error()."<br />"; 

更进一步,你在做什么是非常不好的做法。尝试制作更新程序,让您定位到会话中,然后更新/刷新页面,并从您离开执行的地方继续。如果您的.htaccess中没有tim_out限制,则不表示任何内容。有时你可能没有设定时间限制。

先尝试刷新页面,看看它是否可以帮助你。你可以使用一个html元标记。或者:

header('Location: thispage.php'); 

并使您的每一步都编入请求。

+0

或者您可以使用ajax。你的选择。请参阅查找以某种方式将您的算法状态保存在任何形式中的方法,您可以选择任并使用超级全局$ _SESSION。 – khael

相关问题