ofbeaton / command-running
Detects if a command or process is currently running.
Requires
- php: >=5.4
Requires (Dev)
- humbug/humbug: ^1.0@dev
- mayflower/php-codebrowser: ^1.1
- ofbeaton/granite: ^0
- phing/phing: ^2.11
- php-mock/php-mock-phpunit: ^0
- phpunit/phpunit: ^4.8
- squizlabs/php_codesniffer: ^2.3
README
Detects if a command or process is currently running and optionally kill it.
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.