duankanjian4642 2014-05-26 04:26
浏览 18
已采纳

PHP脚本如何不终止?

I'm on shared hosting and constantly get over process limit errors. Support said if traffic is low then it's because inefficient scripts are not terminated. Since I'm on a shared host and I only create the .php files, I don't really get how my scripts which only serve pages (that is they are called by Apache when a request coming in and they create and display the page) could not terminate.

Is it possible a script can linger on even if it's finished its job? Is there a way to make a script terminate other than exiting when end of file is reached?

My scripts are regular PHP scripts, they fetch data from the database, create the HTML and then exit. They do not do anything special.

  • 写回答

2条回答 默认 最新

  • duanchazhou6779 2014-05-26 04:32
    关注

    Your PHP Script is running in a Loop which creates the HTML.

    1. It total depends on how much records are coming out of your database.
    2. Their maybe some sort of leakage in your Query which is making it heavy on the Server.
    3. The loop will only end after it's done with it's JOB.

    Please paste some code so that we can investigate and help you out. At this time, this all I can say as mentioned above.

    You can track down how long does it take for the script to run

    <?php 
        /* Put this first thing before the loop begins */
        echo "Start " . date("Y-m-d H:i:s"); 
    ?>
    
    <?php 
        /* Put this at the end of your script */
        echo "End " . date("Y-m-d H:i:s"); 
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dsy19811981 2014-05-26 04:38
    关注

    You can setting set execution limit http://www.php.net/manual/en/function.set-time-limit.php

    If you mean execute result set with big number data and don't want tobe terminated until all data get executed for example sending mail for each user in your database and wait till all user get mail then it can send new mail to that user you can use web cron instead http://www.mywebcron.com limit send email for 20 user only, and update it send status to true so it send only to false send status

    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于网上一个easyx制作的见缝插针小游戏(c++)
  • ¥15 开地址法双散列函数处理碰撞
  • ¥15 想问一下这个是什么情况 虚拟机Linux打不开了
  • ¥15 联通光猫掉注册了怎么重新注册上去
  • ¥15 关于unity开发steamvr程序遇到的问题
  • ¥60 求tc downloader的下载方式
  • ¥15 华为 快捷方式 手电筒 接口
  • ¥15 Qt6.5支不支持Android13开发啊
  • ¥20 网络只能跑一半,应该如何设置
  • ¥20 Python调用百度开发者平台人脸识别接口