public function init() { $this->checkStatus(); $pid = posix_getpid(); file_put_contents($this->cacheDir . "/pid", $pid); $server_type = $this->server_type; $server = $this->config['server']; $server = $server[$server_type]; $server = $server_type . "://" . $server['host'] . ":" . $server['port'] . "/"; $server = new HproseSwooleServer($server); $server->set($this->config['setting']); $this->server = $server; $server->server->on('WorkerStart', array($this, 'blindClass')); $server->start(); }
// swoole 1.7.16+ function asyncHello($name, $callback) { swoole_timer_after(3000, function () use($name, $callback) { $callback("Hello async {$name}!"); }); } class TestModel { public function edg() { return 'one'; } } class B { public function aa() { return "ced"; } } $server = new HproseSwooleServer("tcp://127.0.0.1:1504"); $server->setErrorTypes(E_ALL); $server->setDebugEnabled(); #$server->addFunction('hello'); $server->add(new TestModel(), '', 'test'); #$server->add(new B(),'b'); #$server->addFunctions(array('e', 'ee')); #$server->addAsyncFunction('asyncHello'); $server->start();
public function swooletcpserverAction() { $server = new HproseSwooleServer("tcp://127.0.0.1:1504"); $server->setErrorTypes(E_ALL); $server->setDebugEnabled(); $server->add(new TestModel(), '', 'test'); $server->start(); }