create() public static method

create a lock instance
public static create ( $key ) : Semaphore
$key
return Semaphore
Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
<?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());
Ejemplo n.º 3
0
 public function __construct()
 {
     $this->sem = \Jenner\SimpleFork\Lock\Semaphore::create("test");
 }