I've been experiencing a strange issue on Debian 9 with PHP 7.1.13. We have a number of PHP scripts setup to run via a crontab at various intervals between every 1 to 15 mins.

Most of the time these run fine and terminate successfully, however occasionally they don't terminate and end up hanging around in memory. There's currently 781 and I cleared them out about 48 hours ago.

The identical system running on Ubuntu 14.04 does not have this problem (running on php 5.6). I've also seen the issue on my development machine which runs Ubuntu 17.10 and php 7, although I thought it was linked to XDebug, which is runnnig on my dev machine.

Has anyone experienced similar issues with background PHP7 tasks? Its easy enough to work around it and write a watchdog script which kills them off after a set period, but I'd rather fix the issue rather than the symptom.



In case anyone else is wondering, I never got to the bottom of this and in the end just (with a bit of a starting push from a friend) came up with this shell script which I just run periodically.

ps aexo etimes,pid,command | grep php | grep -v "pubsub" | awk '{if ($1 >= 3600) print $2}' | while read pid; do kill $pid; done

The grep -v "pubsub" bit is just so that I don't kill the pubsub server, which quite legitimately can run for days / weeks without issue. You can remove this if you don't have any processes to exclude

Note, the etimes argument to ps won't work on some older distros, without it getting the elapsed time since start in seconds is hard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.