PHP code example of chongyi / keeper

1. Go to this page and download the library: Download chongyi/keeper 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/ */

    

chongyi / keeper example snippets



use Dybasedev\Keeper\Http\ServerProcess;
use Dybasedev\Keeper\Http\Lifecycle\HttpLifecycleTrait;
use Dybasedev\Keeper\Http\Lifecycle\Illuminate\LifecycleTrait;

use Illuminate\Routing\Router;

class Http extends ServerProcess
{
    use HttpLifecycleTrait, LifecycleTrait;

    protected function getRoutesRegistrar()
    {
        return function (Router $router) {
            $router->get('/', function () {
                return 'hello, world';
            });
        };
    }
}


use Dybasedev\Keeper\Process\ProcessManager;

class Master extends ProcessManager
{
    protected function onPreparing() 
    {
        $options = [
            'host'        => '0.0.0.0',
            'port'        => '19730',
            'auto_reload' => false // 该子进程退出后是否自动重载
        ];
        
        // 注册子进程
        $this->registerChildProcess(new Http($options));
    }
    
}


// 确保引入了 autoload.php
// ile('./pid')->setDaemon(true);

// 启动
$master->run();

// 重启
$master->restart();

// 停止
$master->stop();