This class is a wrapper for OS and PID files

Installs: 72

Dependents: 0

Stars: 3

Watchers: 1

Forks: 1

Open Issues: 1

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


Latest Stable Version Build Status Scrutinizer Code Quality Code Coverage License


This class is made by unreal4u (Camilo Sperberg).

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

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.


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:


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


  • 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