ofbeaton/command-running

Detects if a command or process is currently running.

1.0.0 2015-08-20 22:23 UTC

This package is not auto-updated.

Last update: 2024-04-27 15:37:04 UTC


README

Detects if a command or process is currently running and optionally kill it.

Latest Stable Version Build Status Dependency Status Total Downloads License

Currently supports:

  • Linux
  • Windows

Please note that getPids() on windows is slow (2 seconds). There may be a way to speed it up using WMI in the future.

Alternatives

If you don't need advanced features, you can use the Symfony Lock component and trait in any application, even non-symfony ones. It is actively maintained and is likely more up to date.

It supports filesystem (FlockStore), shared memory (SemaphoreStore) and even databases and Redis servers.

It does not support force claims, kills, or reports.

Updates

The project is considered in a usable state and feature complete.

This project is used in corporate applications. As such, the authors are unlikely to update it on a regular basis, but instead when the corporate applications that use it run into problems. You should expect updates in the 5-10yr range.

Issues and PRs will be monitored, and we will continue to work with the community to provide updates as they are contributed.

Installing via Composer

The recommended way to install Command Running is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php

Next, run the Composer command to install the latest stable version:

composer.phar require ofbeaton/command-running

After installing, you can now use it in your code:

    $pidfile = 'mypidfile.txt';
    $running = new \Ofbeaton\Command\Running($pidfile);

    $ok = $running->claimPidFile();
    if ($ok === false) {
        echo 'We are currently already running'.PHP_EOL;
        exit;
    }

    // your code

    // at the end of your program
    $running->releasePidFile();

For more detailed usage, see the Forever Example.

License

This software is distributed under the MIT License. Please see License file for more information.