public function testCommunication() { if (version_compare(PHP_VERSION, '5.6.0') < 0) { $this->markTestSkipped("php version is too low"); } $process = new \Jenner\SimpleFork\Process(function () { $lock = \Jenner\SimpleFork\Lock\Semaphore::create('test'); $lock->acquire(false); sleep(5); $lock->release(); }); $process->start(); sleep(3); $lock = \Jenner\SimpleFork\Lock\Semaphore::create("test"); $this->assertFalse($lock->acquire(false)); $process->wait(); $this->assertTrue($lock->acquire(false)); $this->assertTrue($lock->release()); }
<?php /** * Created by PhpStorm. * User: Jenner * Date: 2015/10/26 * Time: 15:49 */ require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; $process = new \Jenner\SimpleFork\Process(function () { $lock = \Jenner\SimpleFork\Lock\Semaphore::create('test'); var_dump($lock->acquire()); sleep(5); var_dump($lock->release()); }); $process->start(); sleep(3); $lock = \Jenner\SimpleFork\Lock\Semaphore::create("test"); $this->assertFalse($lock->acquire()); $process->wait(); $this->assertTrue($lock->acquire()); $this->assertTrue($lock->release());
public function release($server, $loop) { return $this->sem->release(); }
public function __construct() { $this->sem = \Jenner\SimpleFork\Lock\Semaphore::create("test"); }