File: examples/job-with-fatal-error.php

Recommend this page to a friend!
  Classes of Camilo Sperberg  >  PID process check  >  examples/job-with-fatal-error.php  >  Download  
File: examples/job-with-fatal-error.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PID process check
Check if a PHP script is running using PID files
Author: By
Last change:
Date: 6 years ago
Size: 728 bytes
 

Contents

Class file image Download
<?php

// Load the class
include('../src/unreal4u/pid.php');

// Enter here for how many seconds this example script should be running
$maxSeconds = 30;

try {
   
$options = array('timeout' => 10);
   
$pid = new unreal4u\pid($options);
} catch (\
Exception $e) {
   
// Ok, you should never call die or exit within your script, but this is just an example file
   
die($e->getMessage().PHP_EOL);
}

if (
$pid->alreadyRunning) {
    die(
sprintf('Already running an instance of this script (pid #%s)'.PHP_EOL, $pid->pid));
}

printf('Not running any instance of %s, this is PID %d'.PHP_EOL, basename(__FILE__), $pid->pid);
sleep(5);

// Produce an intentional fatal error, this will NOT delete the PID
require('i-should-not-exist');


For more information send a message to info at phpclasses dot org.