Skip to content

Instantly share code, notes, and snippets.

@MattKetmo
Created November 13, 2013 14:17
Show Gist options
  • Save MattKetmo/7449828 to your computer and use it in GitHub Desktop.
Save MattKetmo/7449828 to your computer and use it in GitHub Desktop.
Playing with LiipProcessManager
<?php
// see https://github.com/liip/LiipProcessManager/
require __DIR__.'/vendor/autoload.php';
use Liip\ProcessManager\ProcessManager;
use Liip\ProcessManager\PidFile;
try {
$lock = new PidFile(new ProcessManager(), '/tmp/foobar');
$lock->acquireLock();
$lock->setPid(getmypid());
echo 'Doing something heavy...';
sleep(5);
echo 'done!'.PHP_EOL;
$lock->releaseLock();
} catch (Exception $e) {
echo 'Unable to do anything'.PHP_EOL;
if (!$lock->isProcessRunning()) {
$lock->releaseLock();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment