Exemplo n.º 1
0
 public function testOn()
 {
     $process = new \Jenner\SimpleFork\Process(function () {
     });
     $process->on(\Jenner\SimpleFork\Process::BEFORE_START, function () {
         $cache = new \Jenner\SimpleFork\Cache\SharedMemory();
         $cache->set('test', 'test');
         return true;
     });
     $process->on(\Jenner\SimpleFork\Process::BEFORE_EXIT, function () {
         $cache = new \Jenner\SimpleFork\Cache\SharedMemory();
         $cache->delete('test');
         sleep(3);
         return true;
     });
     $cache = new \Jenner\SimpleFork\Cache\SharedMemory();
     if ($cache->has('test')) {
         $cache->delete('test');
     }
     $process->start();
     sleep(1);
     $this->assertEquals('test', $cache->get('test'));
     $cache->delete('test');
 }
Exemplo n.º 2
0
<?php

/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/8/13
 * Time: 9:53
 */
declare (ticks=1);
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
class TestRunnable implements \Jenner\SimpleFork\Runnable
{
    /**
     * 进程执行入口
     * @return mixed
     */
    public function run()
    {
        while (true) {
            echo "I am running" . PHP_EOL;
            sleep(1);
        }
    }
}
$process = new \Jenner\SimpleFork\Process(new TestRunnable());
$process->on(\Jenner\SimpleFork\Process::BEFORE_EXIT, function () {
    return true;
});
$process->start();
sleep(5);
$process->shutdown();
Exemplo n.º 3
0
/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/8/20
 * Time: 14:37
 */
declare (ticks=1);
require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
class TestRunnable implements \Jenner\SimpleFork\Runnable
{
    /**
     * 进程执行入口
     * @return mixed
     */
    public function run()
    {
        while (true) {
            echo "I am running" . PHP_EOL;
            sleep(1);
        }
    }
}
$process = new \Jenner\SimpleFork\Process(new TestRunnable());
$process->on(\Jenner\SimpleFork\Process::BEFORE_START, function () {
    echo "start" . PHP_EOL;
    return true;
});
$process->start();
sleep(5);
$process->shutdown();