PHP shell_exec waiting for script to finish?

I have a PHP script that queries the database for a list of jobs and runs other PHP scripts based on what it finds in the database (mainly the process queue).

Some scripts executed by runer run script may take about 30 seconds (creating PDF files, resizing images, etc.).

The problem is that shell_exec() in the queue runs the script calls the processing scripts, but then they do not wait for their completion, as a result of which the queue will not be completed.

Script queue statement:

 #!/usr/bin/php <?php // Loop through database and find jobs to be done shell_exec(sprintf("/root/scripts/%s.php", $row['jobName'])); ?> 

Script task:

 #!/usr/bin/php <?php shell_exec("/usr/bin/htmldoc -t pdf --webpage test.html > test.pdf"); // Update database to mark job as completed ?> 

Executing a script job directly from the command line and creating a PDF file.

Any ideas on how to fix this? Or is there a better way to start a process queue?

+6
source share
1 answer

Try the following:

 shell_exec("nohup /usr/bin/htmldoc -t pdf --webpage test.html > test.pdf 2>&1 &"); 
+7
source

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


All Articles