File: examples/simple-example.php

Recommend this page to a friend!
  Classes of Camilo Sperberg  >  PID process check  >  examples/simple-example.php  >  Download  
File: examples/simple-example.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: Possibility to pass on the arguments as either an array or via variables

- Also improved documentation
- Tested all example files and adjusted where needed
- Updated unit test to include at least once the new model
- More tests needed!
Date: 6 years ago
Size: 613 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 {
   
$pid = new unreal4u\pid();
} catch (\
Exception $e) {
   
// Calling die() is actually a bad practice, but this is just an example file
   
die($e->getMessage().PHP_EOL);
}

if (!
$pid->alreadyRunning) {
   
longRunningFunction($maxSeconds, $pid->pid);
} else {
    die(
'Script was already running, so we had to terminate the execution of it'.PHP_EOL);
}


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