Note that there are some explanatory texts on larger screens.

plurals
  1. POProcess Continues Running After PHP Fatal Error
    primarykey
    data
    text
    <p>I have the following shell script which I am running every minute in cron to make sure that a copy of a PHP script is always running:</p> <pre><code>MY_DIR=`dirname $0` /usr/local/bin/setlock -n /tmp/newdb.$1.lock /usr/local/bin/php $MY_DIR/background/$1.php </code></pre> <p>Which is called via cronjob:</p> <pre><code>* * * * * ~/mysite/background-process.sh new-min-max-dispatcher </code></pre> <p>The php scripts it is running are designed to do tasks that take around 30 minutes and then exit, after which cron will relaunch the process. This works almost all of the time, but every once in a while the process never exits. It seems to happen when the script produces a lot of output on <code>STDERR</code>.</p> <p>However, I can't reproduce that behaviour by simply forcing the script to output similar amounts to <code>STDERR</code>. In <code>ps</code>, I can see that both the process and the <code>sh</code> call from crontab are still running. I've been trying to figure out why this is happening for months, including putting extra code into every while loop to <code>die()</code> and email me if the loop is going for more than a reasonable amount of time.</p> <p>Today I got an important piece of evidence. After finding the process had been running for two days and killing it, I get emailed the STDERR from the script by cronjob, ending with:</p> <pre><code>Fatal error: Maximum execution time of 3600 seconds exceeded in /home/myuser/mysite/inc/browser.php on line 102 /home/myuser/mysite/background-process.sh: line 2: 28189 Terminated /usr/local/bin/setlock -n -x /tmp/newdb.$1.lock /usr/local/bin/ </code></pre> <p>I'm not worried about the fact that the PHP script reached it's maximum execution time - that can happen. I want to know why if the PHP script had died from a fatal error, the process was still hanging around in ps, along with the sh command cron used to launch it:</p> <pre><code>myuser 32091 0.0 0.0 8892 1104 ? Ss Oct28 0:00 /bin/sh -c ~/mysite/background-process.sh new-min-max-dispatcher myuser 32142 46.7 5.2 328788 131920 ? R Oct28 63:24 /usr/local/bin/php /home/myuser/mysite/background/new-min-max-dispatcher.php </code></pre> <p>As I see it, the php command should have ended with the Fatal Error, causing the setlock to complete, the background-process.sh script to finish, and the whole cronjob to be done. I suspect that there might be something weird going on because of the piping of streams or some side effect of setlock. I don't know enough about either to even know where to look next.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload