Linux: Cron job to monitor for php-fpm service problem


Sometimes, php-fpm service is error, how to monitor for php-fpm service ?

Step 1: create a file like check.php with a simple content like

<?php
echo "1";

and upoad this file to document root (like: /home/vpssim.demo/public_html), you will have the link: http://localhost/check.php

Step 2: add a cron job:

*   *   *   *   *    /usr/bin/curl --head -sf http://localhost/check.php -o /dev/null || /usr/sbin/service php-fpm restart

You can use the command line

crontab -e

Then type: i
Then type:

*   *   *   *   *    /usr/bin/curl --head -sf http://localhost/check.php -o /dev/null || /usr/sbin/service php-fpm restart

Then type: :w
Then type: :q

Done! now when php-fpm is error, this service will be restarted

To see list of cron jobs, you can use command

crontab -l

Related Post

No comments yet.

Leave a Reply