I am using kannel to send SMS via PHP. I want to know how can I check if a particular process is running. For kannel to run, a process named bearerbox
should be running all time. I want to check if this process is running or not. Because if the process is not running then a mail will be sent to me notifying me about it.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
There are a lot of ways to deal with this. The easiest (and a direct answer to your question) is to grab the output of 'ps'.
Deamons tend to always create a 'pid' file though. This file contains the process-id of the daemon. If yours has that, you can check the contents of the file and see if the process with that id is still running. This is more reliable.
supervisord might also have this functionality. Lastly, maybe it's better to get a real monitoring system rather than build something yourself. Nagios might be a good pick, but there might be others.
You can use the exec command to find your process and then act accordingly.
Something like:
exec('ps aux | grep bearerbox', $output);
You'll need to work out what is returned on your server to decide if it's running or not.
Good luck.
This is the best way
in the above code gs is the process that I was checking
Simple yet handy solution to monitor processes through PHP: PHP-Linux-Process-Monitor.
The code goals like:
The easiest is to use
pgrep
, which has an exit code of 0 if the process exists, 1 otherwise.Here's an example.