How do you get a Cronjob executing a PHP script to run longer than 30 seconds?

可紊 提交于 2019-12-01 23:33:24

There are several things that could be terminating your script. One could be the maximum execution time set in the php.ini file. If that's the case, you can override it in your script with set_time_limit(0); where zero means no limit and any number greater than zero is the number of seconds to allow the script to run for before being terminated. It's important to note that this time does NOT include the time it takes for the browser to make the request, so file upload time wouldn't count here.

If you're in a shared hosting environment (like Dreamhost), they have process watches that will kill off any PHP process after a set time limit. You cannot get around these. You would need to contact the hosting provider to see what you need to do to get access to run the script for longer (for Dreamhost, they want you to have a they're PS offering).

Lars D

Use this syntax to start php:

php -c /path/to/another/php.ini /this/is/the/file/cron.php

Then you can specify a different timeout (or no timeout) in a different php.ini file.

Joe
ini_set('max_execution_time', 600);

Add this to the top of your php file and it will run for 600 seconds. Anything more is not recommended but you can have a go if you want.

Brendon-Van-Heyzen

I would just use wget http://path.to.myscript.php

If it's dying after 30 you may need to set max_execution_time = 60 in your php.ini to allow the script to run longer than 30 seconds.

sole

You could also use ini_set('max_execution_time', 60)

But as the manual page says, in some cases (i.e. running in safe mode) this will have no effect at all: http://uk.php.net/manual/en/info.configuration.php#ini.max-execution-time

It could also be possible that the php.ini for client line has different max execution values than for the browser. I have seen it sometimes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!