PHP Classes

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: Update of examples/simple-example.php
Date: 1 month 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);
}