static public autoCreate ( $host, $port, boolean $ssl = false ) : |
||
$host | ||
$port | ||
$ssl | boolean | |
return |
static function autoCreate($host, $port, $ssl = false)
{
if (class_exists('\\swoole_server', false)) {
return new self($host, $port, $ssl);
} elseif (function_exists('event_base_new')) {
return new EventTCP($host, $port, $ssl);
} else {
return new SelectTCP($host, $port, $ssl);
}
}
static function create($ini_file = null) { $opt = getopt('m:h:p:d:'); //mode, server or fastcgi if (empty($opt['m'])) { $opt['m'] = 'server'; } //daemonize if (empty($opt['d'])) { $opt['d'] = false; } if ($opt['m'] == 'fastcgi') { $protocol = new Swoole\Protocol\AppFPM(); } else { $protocol = new Swoole\Protocol\AppServer(); } if ($ini_file) { $protocol->loadSetting($ini_file); //加载配置文件 } //port if (!empty($opt['p'])) { $protocol->default_port = $opt['p']; } elseif (!empty($protocol->config['server']['port'])) { $protocol->default_port = $protocol->config['server']['port']; } else { $protocol->default_port = self::DEFAULT_PORT; } //host if (!empty($opt['h'])) { $protocol->default_host = $opt['h']; } elseif (!empty($protocol->config['server']['host'])) { $protocol->default_host = $protocol->config['server']['host']; } else { $protocol->default_host = self::DEFAULT_HOST; } $server = Swoole\Network\Server::autoCreate($protocol->default_host, $protocol->default_port); $server->setProtocol($protocol); if (!empty($protocol->config['server']['worker_num'])) { $server->runtimeSetting['worker_num'] = $protocol->config['server']['worker_num']; } return $protocol; }