function my_onStart(swoole_server $serv) { global $argv; swoole_set_process_name("php {$argv[0]}: master"); echo "MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}\n"; echo "Server: start.Swoole version is [" . SWOOLE_VERSION . "]\n"; }
/** * 设置进程名 */ private static function set_process_name() { if (!function_exists("swoole_set_process_name")) { self::exit2p("Please install swoole extension.http://www.swoole.com/"); } swoole_set_process_name(self::$process_name); }
public static function run($fd) { self::$fp = fopen("php://fd/" . $fd, "a"); swoole_set_process_name(self::$name); self::http_server(); self::start(); }
protected function start() { if ($this->pidManager->get()) { echo "ERROR: plumber is already running.\n"; return; } echo "plumber started.\n"; if ($this->config['daemonize']) { swoole_process::daemon(); } $this->logger = new Logger(['log_path' => $this->config['log_path']]); $this->output = new Logger(['log_path' => $this->config['output_path']]); $this->logger->info('plumber starting...'); $this->stats = $stats = $this->createListenerStats(); swoole_set_process_name('plumber: master'); $this->workers = $this->createWorkers($stats); $this->registerSignal(); $this->pidManager->save(posix_getpid()); swoole_timer_tick(1000, function ($timerId) { $statses = $this->stats->getAll(); foreach ($statses as $pid => $s) { if ($s['last_update'] + $this->config['reserve_timeout'] + $this->config['execute_timeout'] > time()) { continue; } if (!$s['timeout']) { $this->logger->notice("process #{$pid} last upadte at " . date('Y-m-d H:i:s') . ', it is timeout.', $s); $this->stats->timeout($pid); } } }); }
private function my_set_process_name($title) { if (substr(PHP_VERSION, 0, 3) >= '5.5') { cli_set_process_title($title); } else { swoole_set_process_name($title); } }
public function onStart() { swoole_set_process_name(SWOOLE_DEAMON); $reload = "echo 'Reloading...'\n"; $reload .= "pid=\$(pidof " . SWOOLE_DEAMON . ")\n"; $reload .= "kill -USR1 \"\$pid\"\n"; $reload .= "echo 'Reloaded'\n"; file_put_contents(__DIR__ . '/reload_' . SWOOLE_DEAMON . '.sh', $reload); }
protected function execute(InputInterface $input, OutputInterface $output) { $operation = $input->getArgument('operation'); swoole_set_process_name("kerisy-rpcserver:manage"); if (!in_array($operation, ['run', "stop", "start", "restart"])) { throw new InvalidParamException('The <operation> argument is invalid'); } return call_user_func([$this, 'handle' . $operation]); }
public function onWorkerStart($server, $worker_id) { global $argv; if ($worker_id >= $server->setting['worker_num']) { swoole_set_process_name("php {$argv[0]} task worker"); } else { swoole_set_process_name("php {$argv[0]} event worker"); } echo "WorkerStart|MasterPid={$server->master_pid}|Manager_pid={$server->manager_pid}|WorkerId={$worker_id}\n"; }
function processRename($serv, $worker_id) { global $argv; if ($worker_id >= $serv->setting['worker_num']) { swoole_set_process_name("php {$argv[0]}: task"); } else { swoole_set_process_name("php {$argv[0]}: worker"); } echo "WorkerStart: MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}"; echo "|WorkerId={$serv->worker_id}|WorkerPid={$serv->worker_pid}\n"; }
public function onWorkerStart($server, $worker_id) { global $argv; opcache_reset(); include_once dirname(__FILE__) . "/test/test.php"; if ($worker_id >= $this->_server->setting['worker_num']) { swoole_set_process_name("php {$argv[0]} task worker"); } else { swoole_set_process_name("php {$argv[0]} event worker"); } }
public function onWorkerStart($server, $workerId) { if ($workerId >= ZConfig::getField('socket', 'worker_num')) { swoole_set_process_name(ZConfig::get('project_name') . " server task num: {$server->worker_id} pid " . $server->worker_pid); } else { swoole_set_process_name(ZConfig::get('project_name') . " server worker num: {$server->worker_id} pid " . $server->worker_pid); } if (function_exists('opcache_reset')) { opcache_reset(); } }
function my_onWorkerStart($serv, $worker_id) { global $argv; if ($worker_id >= $serv->setting['worker_num']) { swoole_set_process_name("php {$argv[0]} task worker"); } else { swoole_set_process_name("php {$argv[0]} event worker"); } //echo "WorkerStart|MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}|WorkerId=$worker_id\n"; //$serv->addtimer(500); //500ms }
/** * 设置进程的名称 * @param $name */ static function setProcessName($name) { if (function_exists('cli_set_process_title')) { cli_set_process_title($name); } else { if (function_exists('swoole_set_process_name')) { swoole_set_process_name($name); } else { trigger_error(__METHOD__ . " failed. require cli_set_process_title or swoole_set_process_name."); } } }
/** * worker start时调用 * @param unknown $serv * @param int $worker_id */ public function onWorkerStart($serv, $worker_id) { global $argv; if ($worker_id >= $serv->setting['worker_num']) { swoole_set_process_name("php {$argv[0]}: task"); } else { swoole_set_process_name("php {$argv[0]}: worker"); } echo "WorkerStart: MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}|WorkerId={$serv->worker_id}|WorkerPid={$serv->worker_pid}\n"; define('APPLICATION_PATH', dirname(__DIR__)); include APPLICATION_PATH . '/httpindex.php'; }
public function processRename($serv, $worker_id) { global $argv; $worker_num = isset($serv->setting['worker_num']) ? $serv->setting['worker_num'] : 1; $task_worker_num = isset($serv->setting['task_worker_num']) ? $serv->setting['task_worker_num'] : 0; if ($worker_id >= $worker_num) { swoole_set_process_name("php {$argv[0]}: task"); } else { swoole_set_process_name("php {$argv[0]}: worker"); } echo $serv->master_pid, '--', $serv->manager_pid, '--', $serv->worker_id, '--', $serv->worker_pid, "\n"; }
public function processRename($serv, $worker_id) { global $argv; $worker_num = isset($serv->setting['worker_num']) ? $serv->setting['worker_num'] : 1; $task_worker_num = isset($serv->setting['task_worker_num']) ? $serv->setting['task_worker_num'] : 0; if ($worker_id >= $worker_num) { swoole_set_process_name("php {$argv[0]}: task"); } else { swoole_set_process_name("php {$argv[0]}: worker"); } echo str_pad($serv->master_pid, self::$_maxMasterPidLength + 2), str_pad($serv->manager_pid, self::$_maxManagerPidLength + 2), str_pad($serv->worker_id, self::$_maxWorkerIdLength + 2), str_pad($serv->worker_pid, self::$_maxWorkerIdLength), "\n"; }
/** * worker start时调用 * @param unknown $serv * @param int $worker_id */ public function onWorkerStart($serv, $worker_id) { global $argv; $worker_num = isset($serv->setting['worker_num']) ? $serv->setting['worker_num'] : 1; $task_worker_num = isset($serv->setting['task_worker_num']) ? $serv->setting['task_worker_num'] : 0; if ($worker_id >= $worker_num) { swoole_set_process_name("php {$argv[0]}: task"); } else { swoole_set_process_name("php {$argv[0]}: worker"); } echo str_pad($serv->master_pid, self::$_maxMasterPidLength + 2), str_pad($serv->manager_pid, self::$_maxManagerPidLength + 2), str_pad($serv->worker_id, self::$_maxWorkerIdLength + 2), str_pad($serv->worker_pid, self::$_maxWorkerIdLength), "\n"; define('APPLICATION_PATH', dirname(__DIR__)); }
public function onWorkerStart($server, $workerId) { $workNum = ZConfig::getField('socket', 'worker_num'); if ($workerId >= $workNum) { swoole_set_process_name(ZConfig::get('project_name') . " server tasker num: " . ($server->worker_id - $workNum) . " pid " . $server->worker_pid); } else { swoole_set_process_name(ZConfig::get('project_name') . " server worker num: {$server->worker_id} pid " . $server->worker_pid); } if (function_exists('opcache_reset')) { opcache_reset(); } Protocol\Request::setSocket($server); }
/** * @param $name */ function process_rename($name) { // hidden Mac OS error。 set_error_handler(function () { }); if (function_exists('cli_set_process_title')) { cli_set_process_title($name); } else { if (function_exists('swoole_set_process_name')) { swoole_set_process_name($name); } } restore_error_handler(); }
function my_onWorkerStart($serv, $worker_id) { global $argv; global $class; opcache_reset(); include "hot_update_class.php"; $class = new HotUpdate(); if ($worker_id >= $serv->setting['worker_num']) { swoole_set_process_name("php {$argv[0]} task worker"); } else { swoole_set_process_name("php {$argv[0]} event worker"); } //echo "WorkerStart|MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}|WorkerId=$worker_id\n"; //$serv->addtimer(500); //500ms }
public function onWorkerStart(\swoole_server $server, $worker_id) { if ($server->taskworker) { swoole_set_process_name('switch_manage_task_worker'); $server->sendMessage('worker start.', $server->worker_id - 1); } else { swoole_set_process_name('switch_manage_event_worker'); if ($worker_id == 0) { //防止tick被重复启动 $server->tick(self::INTERVAL_PING, function () use($server) { $server->task('Ping'); }); } } }
/** * 启动服务 */ public static function start() { if (file_exists(self::$pid_file)) { syslog(LOG_INFO, 'pid file [' . self::$pid_file . '] is exists'); return; } //后台运行 \swoole_process::daemon(); //设置进程名称 \swoole_set_process_name(self::$process_name); self::get_pid(); self::write_pid(); self::registerSignal(); self::startUp(); defined('PHPKIT_RUN_DEBUG') && syslog(LOG_INFO, self::$process_name . ' start success'); }
public function __construct() { $http = new swoole_http_server("0.0.0.0", 9501); $http->set(array('worker_num' => 50, 'daemonize' => true, 'max_request' => 10000, 'dispatch_mode' => 16)); $http->setGlobal(HTTP_GLOBAL_ALL); $http->on('Start', function () { if (function_exists('cli_set_process_title')) { cli_set_process_title('app_server'); } else { if (function_exists('swoole_set_process_name')) { swoole_set_process_name('app_server'); } } }); $http->on('Request', array($this, 'onRequest')); $http->start(); }
public function onWorkerStart(swoole_server $serv, $workerId) { opcache_reset(); // $loader = require __ROOT__.'/vendor/autoload.php'; // $loader->setUseIncludePath(true); //设置不同进程名字,方便grep管理 if (PHP_OS !== 'Darwin') { if ($workerId >= $serv->setting['worker_num']) { swoole_set_process_name("php {$this->servName}: task"); } else { swoole_set_process_name("php {$this->servName}: worker"); } } // 判定是否为Task Worker进程 if ($workerId >= $serv->setting['worker_num']) { } }
function my_onWorkerStart($serv, $worker_id) { global $argv; if ($worker_id >= $serv->setting['worker_num']) { swoole_set_process_name("php {$argv[0]}: task"); } else { swoole_set_process_name("php {$argv[0]}: worker"); } echo "WorkerStart: MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}"; echo "|WorkerId={$serv->worker_id}|WorkerPid={$serv->worker_pid}\n"; // if ($worker_id == 2) // { // $serv->addtimer(2000); //500ms // $serv->addtimer(6000); //500ms // var_dump($serv->gettimer()); // } }
static function run() { self::spl_autoload_register(); swoole_set_process_name('lzm_Crontab'); self::load_config(); $run = true; echo "正在启动..."; while ($run) { $s = date("s"); if ($s == 0) { self::register_timer(); $run = false; } else { echo "启动倒计时 " . (60 - $s) . " 秒\n"; sleep(1); } } }
public function run() { $this->serv->on('Start', array($this->client, 'onStart')); $this->serv->on('Connect', array($this->client, 'onConnect')); $this->serv->on('Receive', array($this->client, 'onReceive')); $this->serv->on('Close', array($this->client, 'onClose')); $this->serv->on('Shutdown', array($this->client, 'onShutdown')); $handlerArray = array('onTimer', 'onWorkerStart', 'onWorkerStop', 'onMasterConnect', 'onMasterClose', 'onTask', 'onFinish'); foreach ($handlerArray as $handler) { if (method_exists($this->client, $handler)) { $this->serv->on(\str_replace('on', '', $handler), array($this->client, $handler)); } } $this->serv->on('ManagerStart', function ($serv) { $name = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : "default"; swoole_set_process_name("ansen: {$name} manager process"); }); $this->serv->start(); }
function processRename(swoole_server $serv, $worker_id) { global $argv; if ($serv->taskworker) { swoole_set_process_name("php {$argv[0]}: task"); } else { swoole_set_process_name("php {$argv[0]}: worker"); } if ($worker_id == 0) { var_dump($serv->setting); } my_log("WorkerStart: MasterPid={$serv->master_pid}|Manager_pid={$serv->manager_pid}|WorkerId={$serv->worker_id}|WorkerPid={$serv->worker_pid}"); }
public function onManagerStart() { \swoole_set_process_name(ZConfig::get('project_name', 'websocket') . ":manager"); }
<?php $serv = new swoole_server("0.0.0.0", 9502); $serv->on('workerstart', function ($server, $id) { global $argv; swoole_set_process_name("php {$argv[0]}: worker"); $local_listener = stream_socket_server("127.0.0.1", 9999); swoole_event_add($local_listener, function ($server) { $local_client = stream_socket_accept($server); swoole_event_add($local_client, function ($client) { echo fread($client, 8192); fwrite($client, "hello"); }); }); }); $serv->on('connect', function (swoole_server $serv, $fd, $from_id) { //echo "connect\n";; }); $serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) { $serv->send($fd, "Swoole: " . $data); //$serv->close($fd); }); $serv->on('close', function (swoole_server $serv, $fd, $from_id) { //var_dump($serv->connection_info($fd)); //echo "onClose\n"; }); $serv->start();