PHP脚本仍在服务器上运行,但网页显示已停止

发布于 2024-12-10 02:55:13 字数 2224 浏览 0 评论 0原文

我编写了一个 PHP 脚本来使用 APNS 推送通知。我添加了一个PHP进度条来监控已经推送了多少用户。 PHP页面中显示进度条。我还不断更新 MySOL 数据库来记录这个数字。该脚本预计将运行很长时间。运行了大约3个小时后,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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恍梦境° 2024-12-17 02:55:13

可能是由于 httpd.conf 中 apache 的配置导致页面显示停止

KeepAliveTimeout 300

由于 php.ini 上的 max_execution_time 属性,PHP 仍在运行

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

謌踐踏愛綪 2024-12-17 02:55:13

请注意,您根本没有调用 mysql_error 函数,请替换该行:

echo "pushlog 表更新错误: ".mysql_error."
";

对此:

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

此外,你所做的事情是非常糟糕的做法。尝试创建一个更新程序,让您保持在会话中,并更新/刷新页面并从您离开执行的位置继续。如果您的 .htaccess 中没有 tim_out 限制,则没有任何意义。有时你可能只是没有设定时间限制。

请先尝试刷新页面,看看是否对您有帮助。您可以为此使用 html 元标记。或者:

header('Location: thispage.php');

并将程序的每一步都变成一个请求。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文