dev-master
9999999-dev https://github.com/TuxCoder/PIDManagerBundlePIDManager for PHP, stop running command twice
MIT
The Requires
- php >=5.3.0
by Norbert Summer
command pid running twice
Wallogit.com
2017 © Pedro Peláez
PIDManager for PHP, stop running command twice
This bundle is intended to prevent running a command twice at the same time., (*1)
When you spool your mails for an example with an cronjob and have a huge amount of mails, it could otherwise happen that the old instance is still sending emails while starting the command a second time., (*2)
The functionality is kept simple. Before executing a command this PIDManager writes the current pid (process id) into a configured file(pid_path). Before running a second time it will check this file and return if the process is still running., (*3)
This Bundle currently only works on Linux, because it detects running processes over the procfs (/proc/$pid)., (*4)
AppKernel.php add the following lines, (*5)
new TuxCoder\PIDManagerBundle\PIDManagerBundle(),
config.yml add the following lines, (*6)
pid_manager:
commands:
- name: swiftmailer:spool:send
pid_path: /run/user/symfony/mail_spool.pid
- name: secoundCommandName
pid_path: /path/to/otherPidFile.pid
$pidManager=new \TuxCoder\PIDManagerBundle\PIDManager();
$pidManager->setPidPath('/path/to/pid/file');
if(!$pidManager->isRunning()) {
$pidManager->setRunning();
//do some cool stuff
$pidManager->setNotRunning();
} else {
//error program is running
}
PIDManager for PHP, stop running command twice
MIT
command pid running twice