Inheritance: implements Jenner\SimpleFork\Lock\LockInterface
 public function __construct($lock_file = "/tmp/react-multi-process.lock")
 {
     if (!file_exists($lock_file)) {
         $touch = touch($lock_file);
         if ($touch === false) {
             throw new \RuntimeException("create lock file failed");
         }
     }
     $this->sem = FileLock::create($lock_file);
 }
Ejemplo n.º 2
0
 public function testCommunication()
 {
     $lock_file = "/tmp/simple-fork.lock";
     if (!file_exists($lock_file)) {
         touch($lock_file);
     }
     $process = new \Jenner\SimpleFork\Process(function () use($lock_file) {
         $lock = \Jenner\SimpleFork\Lock\FileLock::create($lock_file);
         $lock->acquire(false);
         sleep(5);
         $lock->release();
     });
     $process->start();
     sleep(3);
     $lock = \Jenner\SimpleFork\Lock\FileLock::create($lock_file);
     $this->assertFalse($lock->acquire(false));
     $process->wait();
     $this->assertTrue($lock->acquire(false));
     $this->assertTrue($lock->release());
 }
Ejemplo n.º 3
0
<?php

/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/10/26
 * Time: 15:50
 */
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
$lock_file = "/tmp/simple-fork.lock";
if (!file_exists($lock_file)) {
    touch($lock_file);
}
$process = new \Jenner\SimpleFork\Process(function () use($lock_file) {
    $lock = \Jenner\SimpleFork\Lock\FileLock::create($lock_file);
    echo getmypid() . PHP_EOL;
    var_dump($lock->acquire());
    sleep(5);
    echo getmypid() . PHP_EOL;
    var_dump($lock->release());
});
$process->start();
sleep(3);
$lock = \Jenner\SimpleFork\Lock\FileLock::create($lock_file);
echo getmypid() . PHP_EOL;
var_dump($lock->acquire());
$process->wait();
echo getmypid() . PHP_EOL;
var_dump($lock->acquire());
echo getmypid() . PHP_EOL;
var_dump($lock->release());