File: examples/complex-example.php

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

Better documentation and typo in example fix
Date: 6 years ago
Size: 1,445 bytes


Class file image Download

// Load the class
// Load common file which will execute a long running function

complexExample {
$_pid = null;

    public function
__construct($timeout=30) {
$options = array('checkOnConstructor' => false);

$this->_pid = new unreal4u\pid($options);

        try {
$options = array(
'filename' => 'myVeryOwnName',
'timeout' => $timeout

        } catch (
unreal4u\pidWriteException $e) {
'I could most probably not write the PID file'.PHP_EOL);
        } catch (
unreal4u\pidException $e) {
'Error detected: '.$e->getMessage().PHP_EOL);
        } catch (\
Exception $e) {
// A normal Exception should not happen too often, but MAY occur anyway in the future
die('Any other exception: '.$e->getMessage().PHP_EOL);

        if (!
$this->_pid->alreadyRunning) {
        } else {
            throw new
Exception(sprintf('Process already running with pid %s', $this->_pid->pid).PHP_EOL);

    public function
runForLong($maxSeconds) {
longRunningFunction($maxSeconds, $this->_pid->pid);

try {
$complexExample = new complexExample(30);
} catch (\
Exception $e) {

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