This package is abandoned and no longer maintained. No replacement package was suggested.

This class is a wrapper for OS and PID files

v2.0.6 2015-04-02 09:33 UTC

This package is auto-updated.

Last update: 2020-10-26 07:57:10 UTC


README

Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License

pid.php

Credits

This class is made by unreal4u (Camilo Sperberg). unreal4u.com/.

About this class

  • Can be used to verify whether a process is already running or not.
  • Is platform independant: Can be used in Windows or Linux. In both, they will call OS specific functions to find out whether the process is running or not.
  • It does not detect previous fatal errors, but it can omit the previous PID file if a given time has passed since the creation.

Detailed description

This package will check if a certain PID file is present or not, and depending on that will:

Create a PID file. If it already exists, will ask the OS to check whether it is still a running process. If for whatever reason, the OS still thinks the process is still running and too much time has passed, the class can overwrite the previous PID file (Thus initiating a new instance). When the object is destroyed, the corresponding PID file will be deleted as well.

Basic usage

include('src/unreal4u/pid.php');
try {
    $pid = new unreal4u\pid();
} catch (\Exception $e) {
    echo $e->getMessage();
}

if ($pid->isAlreadyRunning) {
    echo 'Your process is already running';
}
  • $pid->pid will show you the pid number.
  • Please see examples for more options and advanced usage
  • There is only one caveat: if you are going to use this class inside a method within a class, ensure that the destructor gets executed when it should: variables are immediatly destroyed after the method finishes executing, so the PID will be destroyed as well. To ensure this, assign the PID class to an object inside the class, that way, whenever that object gets destroyed, this class will be as well.

Composer

This class has support for (preferably) Composer install. Just add the following section to your composer.json with:

{
    "require": {
        "unreal4u/pid": "@stable"
    }
}

Now you can instantiate a new pid class by executing:

require('vendor/autoload.php');

try {
    $pid = new unreal4u\pid();
} catch (\Exception $e) {
    // Do something
}

Pending

  • Better (more thorough) code coverage on PHPUnit tests.
  • Test this class thoroughly on a windows machine, many UNIX improvements has been made in the meantime.

Version History

  • 1.0 :
    • Initial version
  • 1.1:
    • Support for Windows PID check
  • 1.3:
    • PHPUnit testing
    • Documentation improved (Created this README actually)
    • More examples
  • 1.3.1:
    • Script now set itself a maximum execution time
  • 1.4.0:
    • Class is now compatible with composer
  • 1.4.2:
    • Better documentation
    • Better code coverage
  • 1.4.5:
    • Travis-CI support
    • Began deprecating old coding standard
  • 2.0.0:
    • Mayor rewrite of basic functioning of the class
    • Variables can now be passed on as an array instead of per variable
    • Class now throws (more) exceptions when something went wrong
    • More tests regarding new functionality
    • Backwards compatibility changes:
      • Class will now throw exceptions when it fails at some part instead of silently failing
      • Function getTSpidFile() renamed to getTimestampPidFile()

Contact the author