skip to Main Content

Not sure if this is even possible but let’s say I run sudo service apache2 restart. Can PHP detect that Apache has restarted? I know it can do error handling if there’s a fatal error https://secure.php.net/manual/en/function.error-get-last.php#92810 but I’m stumped on whether or not PHP can tell if Apache has restarted. Thanks!

2

Answers


  1. You could have a CRON job running every minute to read the logs of httpd found under /var/log/httpd/error_log (or similar). Then complete a regex check for
    -- resuming normal operations in the log file, pull each item’s datetime and compare it with the current datetime.

    Login or Signup to reply.
  2. You could look at the file modified time of the httpd.pid file using filemtime.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search