2017 © Pedro Peláez
 

library pid_manager

PIDManager for PHP, stop running command twice

image

tuxcoder/pid_manager

PIDManager for PHP, stop running command twice

  • Wednesday, June 3, 2015
  • by TuxCoder
  • Repository
  • 1 Watchers
  • 1 Stars
  • 23 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

SymfonyPIDManager

Description

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)

Function

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)

Warning

This Bundle currently only works on Linux, because it detects running processes over the procfs (/proc/$pid)., (*4)

Usage

With Symfony2

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

Without Symfony2

$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
}

TODO

  • Write some Tests
  • Add an event handler for "AllreadyRunningException".
  • If requested also make it runnable on Windows, Mac, BSD....

The Versions

03/06 2015

dev-master

9999999-dev https://github.com/TuxCoder/PIDManagerBundle

PIDManager for PHP, stop running command twice

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Norbert Summer

command pid running twice