Ejemplo n.º 1
0
if (!isset($arguments['listen'])) {
    \ServerBench\Cli\printf_and_exit("argument --listen or -l should be set.\n");
}
$listen_addr = explode(',', $arguments['listen']);
if (!isset($arguments['ipcs'])) {
    \ServerBench\Cli\printf_and_exit("argument --ipcs should be set.\n");
}
$ipcs = explode(',', $arguments['ipcs']);
if (count($ipcs) != 2) {
    \ServerBench\Cli\printf_and_exit("argument --ipcs should be a couple of sock files.\n");
}
$api = null;
$app_path = $arguments->get('app');
ProcessUtil::setTitle($arguments->get('title', 'serverbench<proxy>'));
try {
    if (isset($app_path) && file_exists($app_path)) {
        $api = new Api('proxy', include $app_path);
    }
    if ($api && false === $api->init()) {
        \ServerBench\syslog_error('app->init(\'proxy\') returns false.');
        exit;
    }
    PeriodicGc::enable(300);
    $proxy = new Proxy($listen_addr, $ipcs);
    $proxy->run();
    if ($api && false === $api->fini()) {
        \ServerBench\syslog_error('app->fini(\'proxy\') returns false.');
    }
} catch (Exception $e) {
    \ServerBench\syslog_error('uncaught exception from proxy: %s', [$e]);
}
Ejemplo n.º 2
0
}
$pid = getmypid();
\ServerBench\syslog_info('pid of controller is %d', [$pid]);
$pidfile = $arguments->get('pidfile');
if (isset($pidfile)) {
    $realpath_pidfile = realpath($pidfile);
    if (file_exists($realpath_pidfile) && file_get_contents($pidfile) != '') {
        \ServerBench\syslog_error('there is a running instance already.');
        exit;
    }
    file_put_contents($pidfile, $pid);
    register_shutdown_function(function () use($pidfile) {
        @unlink($pidfile);
    });
}
ProcessUtil::setTitle($arguments->get('title', 'serverbench<controller>'));
try {
    $api = new Api('controller', include $app_path);
    if (false === $api->init()) {
        \ServerBench\syslog_error('app->init(\'controller\') returns false.');
        exit;
    }
    PeriodicGc::enable(300);
    $controller = new Controller();
    $controller->run(['groups' => [['proxy' => ['routine' => [$phpbin, ['-r', sprintf('require(\'%s\');', __DIR__ . '/start_proxy.php'), '--', '--title', sprintf('%s<proxy>', $title), '--listen', $listen_addr, '--app', $app_path, '--ipcs', $ipcs]]], 'worker' => ['routine' => [$phpbin, ['-r', sprintf('require(\'%s\');', __DIR__ . '/start_worker.php'), '--', '--title', sprintf('%s<worker>', $title), '--app', $app_path, '--ipcs', $ipcs]], 'num' => $workers]]]], $dir);
    if (false === $api->fini()) {
        \ServerBench\syslog_error('app->fini(\'controller\') returns false.');
    }
} catch (Exception $e) {
    \ServerBench\syslog_error('uncaught exception from controller: %s', [$e]);
}
Ejemplo n.º 3
0
if (!isset($app_path)) {
    \ServerBench\Cli\printf_and_exit("arugment --app should be set.\n");
}
if (!file_exists($app_path)) {
    \ServerBench\Cli\printf_and_exit("app(%s) does not exist.", $app_path);
}
if (!isset($arguments['ipcs'])) {
    \ServerBench\Cli\printf_and_exit("argument --ipcs should be set.\n");
}
$ipcs = explode(',', $arguments['ipcs']);
if (count($ipcs) != 2) {
    \ServerBench\Cli\printf_and_exit("argument --ipcs should be a couple of sock files.\n");
}
ProcessUtil::setTitle($arguments->get('title', 'serverbench<worker>'));
try {
    $api = new Api('worker', include $app_path);
    if (false === $api->init()) {
        \ServerBench\syslog_error('app->init(\'worker\') returns false.');
        exit;
    }
    PeriodicGc::enable(300);
    $worker = new Worker($ipcs, function ($message) use($api) {
        return $api->process($message);
    });
    $worker->run();
    if (false === $api->fini()) {
        \ServerBench\syslog_error('app->fini(\'worker\') returns false.');
    }
} catch (Exception $e) {
    \ServerBench\syslog_error('uncaught exception from worker: %s', [$e]);
}