本文整理汇总了PHP中swoole_server::start方法的典型用法代码示例。如果您正苦于以下问题:PHP swoole_server::start方法的具体用法?PHP swoole_server::start怎么用?PHP swoole_server::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swoole_server
的用法示例。
在下文中一共展示了swoole_server::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
function run($setting = array())
{
$set = array_merge($this->swooleSetting, $setting);
$this->sw->set($set);
$version = explode('.', SWOOLE_VERSION);
//1.7.0
if ($version[1] >= 7) {
$this->sw->on('ManagerStart', function ($serv) {
global $argv;
Swoole\Console::setProcessName('php ' . $argv[0] . ': manager');
});
}
$this->sw->on('Start', array($this, 'onMasterStart'));
$this->sw->on('WorkerStart', array($this->protocol, 'onStart'));
$this->sw->on('Connect', array($this->protocol, 'onConnect'));
$this->sw->on('Receive', array($this->protocol, 'onReceive'));
$this->sw->on('Close', array($this->protocol, 'onClose'));
$this->sw->on('WorkerStop', array($this->protocol, 'onShutdown'));
if (is_callable(array($this->protocol, 'onTimer'))) {
$this->sw->on('Timer', array($this->protocol, 'onTimer'));
}
if (is_callable(array($this->protocol, 'onTask'))) {
$this->sw->on('Task', array($this->protocol, 'onTask'));
$this->sw->on('Finish', array($this->protocol, 'onFinish'));
}
$this->sw->start();
}
示例2: start
/**
* 启动服务器
* @return void
*/
public function start()
{
if ($this->isStart) {
return;
}
$this->isStart = true;
$this->server->start();
}
示例3: run
function run($host, $port)
{
register_shutdown_function(array($this, 'errorHandler'));
$this->serv = new swoole_server($host, $port);
file_put_contents(PID_FILE_NAME, posix_getpid());
$this->serv->set(array('max_request' => 0, 'open_length_check' => true, 'package_max_length' => 81920, 'package_length_type' => 'n', 'package_length_offset' => 0, 'package_body_offset' => 2, 'worker_num' => 2));
$this->serv->on('receive', array($this, 'onReceive'));
$this->serv->on('close', array($this, 'onClose'));
$this->serv->start();
}
示例4: run
function run($_setting = array())
{
$default_setting = array('worker_num' => 4, 'open_eof_check' => true, 'open_eof_split' => true, 'package_eof' => self::EOF);
$this->pid_file = $_setting['pid_file'];
$setting = array_merge($default_setting, $_setting);
$serv = new \swoole_server('0.0.0.0', self::SVR_PORT_AOP, SWOOLE_PROCESS, SWOOLE_TCP);
$serv->set($setting);
$serv->on('receive', array($this, 'onReceive'));
$this->serv = $serv;
$this->serv->start();
}
示例5: Bootstrap
public function Bootstrap()
{
$initParams = ['serv_host' => '0.0.0.0', 'serv_port' => '13123', 'serv_mode' => SWOOLE_PROCESS, 'sock_type' => SWOOLE_SOCK_TCP];
Application::RegisterClass(\swoole_server::class, $initParams);
$this->swoole = Application::GetInstance(\swoole_server::class);
$this->setConfig();
$this->initProxy();
//构造时已经自动完成了回调注册
$this->initMonitor();
echo $this->formatSettings($this->swoole);
$this->swoole->start();
}
示例6: serve
public function serve()
{
$support_callback = ['start' => [$this, 'onStart'], 'managerStart' => [$this, 'onManagerStart'], 'workerStart' => [$this, 'onWorkerStart'], 'receive' => [$this, 'onReceive'], 'task' => null, 'finish' => null, 'workerStop' => [$this, 'onWorkerStop']];
foreach ($support_callback as $name => $callback) {
// If has the dependency injection
if (is_callable(Di::get($name))) {
$callback = Di::get($name);
}
if ($callback !== null) {
$this->serv->on($name, $callback);
}
}
$this->serv->set($this->swoole_config);
$this->serv->start();
}
示例7: actionRun
public function actionRun()
{
$serv = new swoole_server("127.0.0.1", 9550);
self::$q_config = (require 'config.php');
$task_num = 0;
foreach (self::$q_config as $key => $val) {
self::$event_base[$key] = $task_num;
self::$cnt[$key] = 0;
$task_num += $val;
}
$this->config['task_worker_num'] = $task_num;
$serv->set($this->config);
$serv->on('Start', array($this, 'my_onStart'));
$serv->on('Connect', array($this, 'my_onConnect'));
$serv->on('Receive', array($this, 'my_onReceive'));
$serv->on('Close', array($this, 'my_onClose'));
$serv->on('Shutdown', array($this, 'my_onShutdown'));
$serv->on('Timer', array($this, 'my_onTimer'));
$serv->on('WorkerStart', array($this, 'my_onWorkerStart'));
$serv->on('WorkerStop', array($this, 'my_onWorkerStop'));
$serv->on('Task', array($this, 'my_onTask'));
$serv->on('Finish', array($this, 'my_onFinish'));
$serv->on('WorkerError', array($this, 'my_onWorkerError'));
$serv->start();
}
示例8: run
public function run()
{
$config = Config::get('socket');
$config = array('worker_num' => 4, 'task_worker_num' => 8, 'max_request' => 10000, 'dispatch_mode' => 2, 'debug_mode' => 0, 'daemonize' => false);
if (isset($argv[1]) and $argv[1] == 'daemon') {
$config['daemonize'] = true;
} else {
$config['daemonize'] = false;
}
$serv = new \swoole_server("0.0.0.0", 8808);
$serv->set($config);
$serv->config = $config;
$handler = new Handler();
$serv->on('Start', array($handler, "start"));
$serv->on('Connect', array($handler, "connect"));
$serv->on('Receive', array($handler, "receive"));
$serv->on('Close', array($handler, "close"));
$serv->on('Shutdown', array($handler, "shutdown"));
$serv->on('Timer', array($handler, "timer"));
$serv->on('WorkerStart', array($handler, "workStart"));
$serv->on('WorkerStop', array($handler, "workStop"));
$serv->on('Task', array($handler, "task"));
$serv->on('Finish', array($handler, "finish"));
$serv->on('WorkerError', array($handler, "workError"));
$serv->start();
}
示例9: __construct
public function __construct()
{
$this->table = new swoole_table(1024);
$this->table->column('serverfd', swoole_table::TYPE_INT, 8);
$this->table->create();
define('APPLICATION_PATH', dirname(dirname(__DIR__)) . "/application");
define('MYPATH', dirname(APPLICATION_PATH));
$this->application = new Yaf_Application(dirname(APPLICATION_PATH) . "/conf/application.ini");
$this->application->bootstrap();
$config_obj = Yaf_Registry::get("config");
$distributed_config = $config_obj->distributed->toArray();
$server = new swoole_server($distributed_config['ServerIp'], $distributed_config['port'], SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
if (isset($distributed_config['logfile'])) {
$server->set(array('worker_num' => 4, 'task_worker_num' => 4, 'dispatch_mode' => 4, 'daemonize' => true, 'log_file' => $distributed_config['logfile']));
} else {
$server->set(array('worker_num' => 4, 'task_worker_num' => 4, 'dispatch_mode' => 4, 'daemonize' => true));
}
require_once __DIR__ . "/DistributedClient.php";
$server->on('Start', array(&$this, 'onStart'));
$server->on('WorkerStart', array(&$this, 'onWorkerStart'));
$server->on('Connect', array(&$this, 'onConnect'));
$server->on('Receive', array(&$this, 'onReceive'));
$server->on('Task', array(&$this, 'onTask'));
$server->on('Finish', array(&$this, 'onFinish'));
$server->on('Close', array(&$this, 'onClose'));
$server->on('ManagerStop', array(&$this, 'onManagerStop'));
$server->on('WorkerError', array(&$this, 'onWorkerError'));
$server->start();
}
示例10: serverrun
public function serverrun($queue)
{
try {
$this->_setting($queue);
} catch (Exception $e) {
throw new \LogicException($e->getMessage());
}
$serv = new swoole_server($this->host, $this->port, $this->mode);
$serv->set($this->config);
$serv->on('Start', array($this->objCallback, 'onStart'));
$serv->on('Receive', array($this->objCallback, 'onReceive'));
$serv->on('Connect', array($this->objCallback, 'onConnect'));
$serv->on('Timer', array($this->objCallback, 'onTimer'));
$serv->on('Task', array($this->objCallback, 'onTask'));
$serv->on('Finish', array($this->objCallback, 'onFinish'));
$serv->on('WorkerStart', array($this->objCallback, 'onWorkerStart'));
$serv->on('WorkerStop', array($this->objCallback, 'onWorkerStop'));
$onArray = array('onShutdown', 'onClose', 'onPipeMessage', 'onManagerStart', 'onManagerStop', 'onWorkerError');
foreach ($onArray as $on) {
if (method_exists($this->objCallback, $on)) {
$serv->on(str_replace('on', '', $on), array($this->objCallback, $on));
}
}
$serv->start();
}
示例11: serve
function serve()
{
$serv = new \swoole_server(SERVERHOST, SERVERPORT);
$serv->on('workerStart', [$this, 'onStart']);
$serv->on('receive', [$this, 'onReceive']);
$serv->set(array('worker_num' => 1, 'dispatch_mode' => 1, 'open_length_check' => true, 'package_max_length' => 8192000, 'package_length_type' => 'N', 'package_length_offset' => 0, 'package_body_offset' => 4));
$serv->start();
}
示例12: run
function run($setting = array())
{
$this->runtimeSetting = array_merge($this->runtimeSetting, $setting);
if (self::$pidFile) {
$this->runtimeSetting['pid_file'] = self::$pidFile;
}
if (!empty(self::$options['daemon'])) {
$this->runtimeSetting['daemonize'] = true;
}
if (!empty(self::$options['worker'])) {
$this->runtimeSetting['worker_num'] = intval(self::$options['worker']);
}
if (!empty(self::$options['thread'])) {
$this->runtimeSetting['reator_num'] = intval(self::$options['thread']);
}
if (!empty(self::$options['tasker'])) {
$this->runtimeSetting['task_worker_num'] = intval(self::$options['tasker']);
}
$this->sw->set($this->runtimeSetting);
$version = explode('.', SWOOLE_VERSION);
//1.7.0
if ($version[1] >= 7) {
$this->sw->on('ManagerStart', function ($serv) {
Swoole\Console::setProcessName($this->getProcessName() . ': manager');
});
}
$this->sw->on('Start', array($this, 'onMasterStart'));
$this->sw->on('Shutdown', array($this, 'onMasterStop'));
$this->sw->on('ManagerStop', array($this, 'onManagerStop'));
$this->sw->on('WorkerStart', array($this, 'onWorkerStart'));
if (is_callable(array($this->protocol, 'onTimer'))) {
$this->sw->on('Connect', array($this->protocol, 'onConnect'));
}
if (is_callable(array($this->protocol, 'onTimer'))) {
$this->sw->on('Close', array($this->protocol, 'onClose'));
}
if (self::$useSwooleHttpServer) {
$this->sw->on('Request', array($this->protocol, 'onRequest'));
} else {
$this->sw->on('Receive', array($this->protocol, 'onReceive'));
}
if (is_callable(array($this->protocol, 'WorkerStop'))) {
$this->sw->on('WorkerStop', array($this->protocol, 'WorkerStop'));
}
//swoole-1.8已经移除了onTimer回调函数
if ($version[1] < 8) {
if (is_callable(array($this->protocol, 'onTimer'))) {
$this->sw->on('Timer', array($this->protocol, 'onTimer'));
}
}
if (is_callable(array($this->protocol, 'onTask'))) {
$this->sw->on('Task', array($this->protocol, 'onTask'));
$this->sw->on('Finish', array($this->protocol, 'onFinish'));
}
$this->sw->start();
}
示例13: run
function run()
{
$serv = new swoole_server("127.0.0.1", 8002);
$serv->set(array('timeout' => 1, 'poll_thread_num' => 1, 'worker_num' => 1, 'backlog' => 128, 'max_conn' => 10000, 'dispatch_mode' => 2));
$serv->on('Receive', array($this, 'onReceive'));
$serv->on('Close', array($this, 'onClose'));
//swoole_server_addtimer($serv, 2);
#swoole_server_addtimer($serv, 10);
$serv->start();
}
示例14: run
function run()
{
$serv = new swoole_server("", 9509);
$serv->set(array('worker_num' => 1, 'max_request' => 0));
$serv->on('WorkerStart', array($this, 'onStart'));
//$serv->on('Connect', array($this, 'onConnect'));
$serv->on('Receive', array($this, 'onReceive'));
//$serv->on('Close', array($this, 'onClose'));
$serv->start();
}
示例15: run
public function run()
{
$serv = new swoole_server('0.0.0.0', 9501);
$serv->on('connect', array($this, 'onConnect'));
$serv->on('receive', array($this, 'onReceive'));
$serv->on('close', array($this, 'onClose'));
$serv->on('workerstart', array($this, 'onWorkerStart'));
$serv->set($this->setting);
$serv->start();
}