PHP code example of loner / reactor

1. Go to this page and download the library: Download loner/reactor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

loner / reactor example snippets


        # 增/改
        $reactor->setRead(resource $stream, callable $listener): bool;
          # 内部回调
          $listener(resource $stream);
      
        # 删
        $reactor->delRead(resource $stream): bool;
        

        # 增/改
        $reactor->setWrite(resource $stream, callable $listener): bool;
          # 内部回调
          $listener(resource $stream);
      
        # 删
        $reactor->delWrite(resource $stream): bool;
        

        # 增/改
        $reactor->setSignal(int $signal, callable $listener): bool;
          # 内部回调
          $listener($signal);
      
        # 删
        $reactor->delSignal(int $signal): bool;
        

        # 增:秒数、回调、是否周期性
        # Loner\Reactor\Timer\Timer
        $reactor->addTimer(float $interval, callable $listener, bool $periodic = false): Timer;
          # 内部回调
          $listener(Timer $timer);
      
        # 删
        $reactor->delTimer(Timer $timer): bool;
        

      # 增:回调、时间规则(分、时、日、月、周,缺省由 * 代替)
      # Loner\Reactor\Crontab\Crontab
      $reactor->addCrontab(callable $listener, string ...$timeRules): Crontab;
        # 内部回调
        $listener(Crontab $crontab);
    
      # 删
      $reactor->addCrontab(Crontab $crontab): bool;
      

    $reactor->loop(): void;
    

    $reactor->destroy(): void;