get_current_user() returns the current owner of the script, not the user executing it. To get the current user executing the script try exec('whoami');
or
$user = posix_getpwuid(posix_getuid());
echo $user['name'];
The old watch dog script idea huh? Not the most elegant way to solve your problem but it can temporarily remedy the situation until you can figure out why its happening in the first place.
The actual problem needs to be addressed, It is either that the server needs to be more finely tuned, or that the server is not powerful enough to handle the load in the first place.
You have determined that the process actually dies. In which case it is as simple as determining if the process still exists. ps aux should do it for you.
for example:
ps aux|grep php-fpm|grep -v grep|awk '{print $2}'
should output the process id of php-fpm. If it does not exist it needs to be restarted
so something along the lines of this should do the trick. (short and simple)
#!/bin/bash
pid=`ps aux|grep php-fpm|grep -v grep|awk '{print $2}'`
if [ $pid == '' ]
then
service php-fpm restart
fi
That script would be run as a crontab every minute. and it has NOT been debugged. so experiment with it and make sure it is working.
The problem with doing that with zombie processes is they actually exist and are "running" but not physically doing anything. in which case they would need to be killed first and then the process restarted.
Again the correct thing to do is to determine what is actually causing the service to crash. The watchdog script idea is only to buy you time.
Hope it helps. Good luck
Best Answer
Recent (5.4+) versions of PHP include a status page with the FPM distribution.
You can configure this separately for each process pool, to show you what is being executed.
Alternatively, you can use APC or Xcache and get status from there.
I personally like Xcache since it shows quite extensive statistics.