Esempio n. 1
0
<?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);
}
Esempio n. 2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$lock = new \EdgarPE\Lock\Lock(__FILE__);
if ($lock->acquire(false)) {
    echo posix_getpid(), "\n";
}
Esempio n. 3
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$lock = new \EdgarPE\Lock\Lock(__FILE__);
$pid = $lock->synchronized(function () {
    return posix_getpid();
});
echo $pid, "\n";