Question

To be simple:

ini_set("max_execution_time") works when I call script.php via classic URL call

ini_set("max_execution_time") doesn't works when script.php is run via exec() function from another php script/process.

Now, my solution is not simply to relay on option 1 because it works, since exec() function that is about to activate script.php and few similar ones is called via (external) cron job.

Does anyone have idea what's happening?

If it's from help below is activating code:

exec('/usr/bin/env php ./script.php');
sleep(30);
exec('/usr/bin/env php ./script2.php');

which activates both script and script2.php and both of them fails when ini_set() returns FALSE.

Was it helpful?

Solution

As Barmar stated above, different PHP.ini files are used for the two versions.

Is the CLI version running in safe mode?

The max_execution_time may not be set at runtime with ini_set() in safe mode. Also, the CLI version defaults to 0 for its execution time limit.

http://php.net/manual/en/info.configuration.php

OTHER TIPS

As Barmar pointed out there are several INI files for php. At least one for CGI and one for CLI. Also you can set some things via ini_set or inside .htaccess. There is some config file which defines which of your settings may be changed where. Quiet possibly you are not allowed to modify the max_execution_time inside a CLI script. If I remember correctly it should be 0 aka unlimited by default.

This could be xdebug if you have it enabled as it defaults the time to 0 (to prevent your scripts timing out when you have a breakpoint set). It might lock it to 0. This was the issue for me.

Use set_time_limit(seconds) instead of ini_set()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top