2

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.

Strayobject
  • 642
  • 11
  • 20
Miloš Đakonović
  • 3,751
  • 5
  • 35
  • 55
  • 4
    When you use `exec()` you're using the CLI configuration of PHP, not the server configuration. – Barmar Feb 22 '13 at 21:31

4 Answers4

1

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.

Christoph Grimmer
  • 4,210
  • 4
  • 40
  • 64
  • Both you and BadAlghoritm pointed out the same thing in same time, and that is correct. I'm giving vote up to both of your answers, and I cannot accept one answer over other. Here is the catch: http://www.php.net/manual/en/features.commandline.differences.php – Miloš Đakonović Feb 22 '13 at 22:07
  • Accept the one from BA. He needs the reps more then I do and it reflects badly on your profile if you do not accept an answer. – Christoph Grimmer Feb 23 '13 at 07:42
  • Ok if you agree. Thanks for response :) – Miloš Đakonović Feb 23 '13 at 09:27
1

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

Community
  • 1
  • 1
BadAlgorithm
  • 117
  • 3
1

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.

Ian
  • 2,898
  • 1
  • 27
  • 29
0

Use set_time_limit(seconds) instead of ini_set()

Winston
  • 1,758
  • 2
  • 17
  • 29