Running php script as cron job - timeout issues?

后端 未结 3 1919
甜味超标
甜味超标 2020-12-29 08:17

I am coding a php script that does some back end stuff and needs to run every 8 hours or so. The script takes a while to execute. For the hell of it, I tried it from my brow

3条回答
  •  一整个雨季
    2020-12-29 08:30

    As default, PHP scripts timesout after 30 seconds which can be overridden by editing the PHP.ini or by adding this at the top of your script.

    set_time_limit(0);
    

    This sets unlimited execution time to your script, that is, it never ends unless the scripts finish execution, or the server goes down, or the file is deleted or any fatal error comes.

    Additionally,

    You can add this to your script and open it in your browser to initiate the script, and it will run as if you are opening it in a browser and keeping the browser open.

    ignore_user_abort();
    

    It simply runs the script in background. These both would be useful for you.

    ADD : When the scripts are run from the commandline,Cli, the default timeout is 0.(No Timeout)

提交回复
热议问题