PHP script is still running on server, but the webpage display has stopped
I wrote a PHP script to push notifications using APNS. I added a PHP progress bar to monitor how many users that have been pushed. The progress bar is displayed in the PHP page. I also keep updating a MySOL database to record the number. This script is expected to run a very long time. After running for about 3 hours, the PHP page (with progress bar) is stopped, but when I check the database, the number of pushed users is still increasing. This means the script is still running in server's memory, but why has the page display stopped?
here is some code:
$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
Perhaps the page display stopped due to the configuration of apache in httpd.conf
KeepAliveTimeout 300
PHP still running due to the property max_execution_time on php.ini
Just to notice, you are not calling the mysql_error function at all, replace the line:
echo "pushlog table update error: ".mysql_error."
";
with this one:
echo "pushlog table update error: ".mysql_error()."<br />";
Further more, what you are doing is very bad practice. Try making an updater, keep you position into a session, and update/refresh the page and continue from where you left the execution. And if you do not have a tim_out limit in your .htaccess doesn't mean anything. And sometimes you might just not set the time limit.
Try refreshing page first, to see if it helps you. You can use a html meta tag for that. or:
header('Location: thispage.php');
And make each step of you program into a request.
精彩评论