File: examples/stale-process.php

Recommend this page to a friend!
  Classes of Camilo Sperberg  >  PID process check  >  examples/stale-process.php  >  Download  
File: examples/stale-process.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: 788 bytes
 

Contents

Class file image Download
<?php

// Load the class
include('../src/unreal4u/pid.php');
// Load common file which will execute a long running function
include('longRunningFunction.php');

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

try {
   
$options = array('filename' => 'staleProcess', 'timeout' => 5);
   
$pid = new unreal4u\pid($options);
} catch (
unreal4u\pidWriteException $e) {
    die(
'I could most probably not write the PID file'.PHP_EOL);
} catch (
unreal4u\pidException $e) {
    die(
'Error detected: '.$e->getMessage().PHP_EOL);
} catch (\
Exception $e) {
    die(
'Another exception: '.$e->getMessage().PHP_EOL);
}

if (
$pid->alreadyRunning) {
    die(
'Process already running with PID #'.$pid->pid.PHP_EOL);
}

longRunningFunction($maxSeconds, $pid->pid);


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