A lengthy PHP script stops when called through exec (), but ends when called through the CLI

I have a bunch of scripts that take a lot of time. Some may take up to 20 minutes.

Here's the Bash script that runs these PHP scripts. When I call this Bash script through the CLI as root, all PHP scripts end without problems. But when I call the Bash script using the PHP exec () function through the browser, the scripts suddenly stop after 7/8 minutes without any errors.

Is there a certain restriction on the execution time of a process or script when executed through Apache / PHP?

I tried:

  • set_time_limit(0)
  • exec('nohup /path/to/bashscript')
  • exec('/path/to/bashscript | at now')

The last two recommended solutions were recommended by others who had problems with long scenarios, but that doesn't help me at all.

Note: The Bash script that runs PHP scripts is a CakePHP console application. I have to execute PHP scripts through this Bash script in order to use all CakePHP functions (models, shell methods, etc.). And I need to be able to call the Bash script through the browser and let it work in the background.

The server is a VPS and WHM / cPanel is installed.

+4
source share
2 answers

you need to increase the maximum runtime with (carefully when you set 0, this makes your runtime infinite)

 ini_set('max_execution_time', 0);

but I would recommend to the user

   proc_open();

over exec(); , . proc_open [] http://www.sitepoint.com/proc-open-communicate-with-the-outside-world/!

+1

Set:

ini_set('max_execution_time', 0);

script. . imo 20 script .

0

Source: https://habr.com/ru/post/1533318/


All Articles