0

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
hakre
  • 193,403
  • 52
  • 435
  • 836
user955461
  • 631
  • 1
  • 6
  • 5

2 Answers2

1

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

linkamp
  • 215
  • 2
  • 5
  • Hi, I checked httpd.conf. There is no KeepAliveTimeout. Do you mean I should add this line? thanks – user955461 Oct 14 '11 at 19:02
  • BTW, I set php max_execution_time to 10 mins with "set_time_limit(600)". The php script is running for more than 3 hours so far, so I guess max_execution_time has nothing do with the script is still running. Thanks – user955461 Oct 14 '11 at 19:06
  • BTW the script terminated after 4 hours – user955461 Oct 14 '11 at 20:03
  • Add KeepAliveTimeout on server config or virtual host config maybe solve your problem – linkamp Oct 15 '11 at 21:27
0

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.

khael
  • 2,600
  • 1
  • 15
  • 36
  • Or you can use ajax. You choice. See to find a way to save your algorithm's state in something, any form you find convenient. And use super global $_SESSION. – khael Oct 14 '11 at 21:52