本文整理汇总了PHP中swoole_server::on方法的典型用法代码示例。如果您正苦于以下问题:PHP swoole_server::on方法的具体用法?PHP swoole_server::on怎么用?PHP swoole_server::on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swoole_server
的用法示例。
在下文中一共展示了swoole_server::on方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bind
/**
* 绑定数据
* @param string $event 事件
* @param object $cls 处理类
* @return void
*/
public function bind($event, $cls)
{
if ($this->isStart) {
return;
}
$this->server->on($event, [$cls, 'handle']);
}
示例2: __construct
public function __construct()
{
$ip = self::$conf['ip'] = empty(self::$conf['ip']) ? '0.0.0.0' : self::$conf['ip'];
$this->serv = new swoole_server($ip, self::$conf['port'], SWOOLE_PROCESS, SWOOLE_TCP);
$this->serv->on('connect', [$this, 'onConnect']);
$this->serv->on('receive', [$this, 'onReceive']);
$this->serv->on('close', [$this, 'onClose']);
}
示例3: 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();
}
示例4: __construct
public function __construct($host, $ip, $config, $bufferDriverClass)
{
$server = new \swoole_server($host, $ip, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
$server->set($config);
$server->on('receive', array($this, 'onReceive'));
$server->on('close', array($this, 'onClose'));
$this->server =& $server;
$this->bufferDriverClass = $bufferDriverClass;
}
示例5: 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();
}
示例6: 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();
}
示例7: 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();
}
示例8:
function __construct($base = false)
{
$mode = $base ? SWOOLE_BASE : SWOOLE_PROCESS;
$serv = new swoole_server("127.0.0.1", 9501, $mode);
$serv->on('Connect', [$this, 'onConnect']);
$serv->on('receive', [$this, '_receive']);
$serv->on('workerStart', [$this, 'onWorkerStart']);
$serv->on('Close', [$this, 'onClose']);
$this->serv = $serv;
}
示例9: 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();
}
示例10: run
function run()
{
$serv = new swoole_server("127.0.0.1", 55151);
$serv->set(array('worker_num' => 1));
$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();
}
示例11: createServer
/**
* 创建server 对象
*
* @return \swoole_server
*/
private function createServer()
{
$server = new \swoole_server($this->host, $this->port, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);
$server->set($this->normalizedConfig());
$server->on('workerStart', [$this, 'onWorkerStart']);
$server->on('connect', [$this, 'onConnect']);
$server->on("receive", [$this, "onReceive"]);
$server->on('close', [$this, 'onClose']);
return $server;
}
示例12: run
function run($setting = array())
{
$this->swooleSetting = array_merge($this->swooleSetting, $setting);
if (!empty($this->swooleSetting['pid_file'])) {
$this->pid_file = $this->swooleSetting['pid_file'];
}
$this->sw->set($this->swooleSetting);
$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('ManagerStop', array($this, 'onManagerStop'));
$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();
}
示例13: __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();
}
示例14: 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();
}
示例15: __construct
public function __construct()
{
//初始化应用
$this->initializationOfApp();
// 创建swoole_http_server对象
$server = new swoole_server("0.0.0.0", 9500);
$server->on('connect', array($this, 'onConnect'));
$server->on('receive', array($this, 'onReceive'));
$server->on('close', array($this, 'onClose'));
$server->start();
}