<?php require_once __DIR__ . '/../../../../vendor/autoload.php'; if ($argc != 4) { exit(-1); } $filename = $argv[1]; $sleep = intval($argv[2]); $wait = boolval($argv[3]); if (dirname(realpath($filename)) !== sys_get_temp_dir()) { exit(-1); } $lock = new \EdgarPE\Lock\Lock(__FILE__); if ($lock->acquire($wait)) { $counter = intval(file_get_contents($filename)); sleep($sleep); file_put_contents($filename, ++$counter); }
<?php require __DIR__ . '/../vendor/autoload.php'; $lock = new \EdgarPE\Lock\Lock(__FILE__); if ($lock->acquire(false)) { echo posix_getpid(), "\n"; }
<?php require __DIR__ . '/../vendor/autoload.php'; $lock = new \EdgarPE\Lock\Lock(__FILE__); $pid = $lock->synchronized(function () { return posix_getpid(); }); echo $pid, "\n";