代码拉取完成,页面将自动刷新
协程客户端,代码
public function onRequest(\Swoole\Http\Request $request, \Swoole\Http\Response $response)
{
$tcp_cli = new \Swoole\Coroutine\Client(SWOOLE_SOCK_TCP);
$tcp_cli->connect('127.0.0.1', 8088);
$tcp_cli->send('test for the coro\n');
$ret = $tcp_cli->recv();
$tcp_cli->close();
if ($ret) {
$response ->end(" swoole response is ok");
}
else{
$response ->end(" recv failed error : {$tcp_cli->errCode}");
}
}
http server多端口监听,代码如下,onReceive不执行,onConnect和onClose多执行,errorCode=110
public function start(){
$this->swoft = new \Swoole\Http\Server($this->http['host'], $this->http['port'], $this->http['model'], $this->http['type']);
$this->swoft->set($this->setting);
$this->swoft->on('start', [$this, 'onStart']);
$this->swoft->on('workerstart', [$this, 'onWorkerStart']);
$this->swoft->on('managerstart', [$this, 'onManagerStart']);
$this->swoft->on('request', [$this, 'onRequest']);
if($this->tcp['enable'] == 1){
$this->listen = $this->swoft->listen($this->tcp['host'], $this->tcp['port'], $this->tcp['type']);
$this->listen->on('connect', [$this, 'onConnect']);
$this->listen->on('receive', [$this, 'onReceive']);
$this->listen->on('close', [$this, 'onClose']);
}
$this->swoft->start();
}
public function onConnect(\Swoole\Server $server, int $fd, int $from_id)
{
var_dump("connnect------");
}
public function onReceive(\Swoole\Server $server, int $fd, int $from_id, string $data)
{
var_dump("receiver---------*******************************__________________");
$server->send($fd, $data);
}
public function onClose(\Swoole\Server $server, int $fd, int $reactorId)
{
var_dump("close------");
}
debug信息
[/tmp/swoole-src-2.0.6/src/network/Server.c:145@swServer_master_onAccept][Master] Accept new connection. maxfd=18|reactor_id=1|conn=19
string(14) "connnect------"
[/tmp/swoole-src-2.0.6/swoole_coroutine.c:331@coro_close]closing coro and 0 remained. usage size: 1363168. malloc size: 2097152
[/tmp/swoole-src-2.0.6/swoole_coroutine.c:263@sw_coro_create]create the 0 coro with stack. heap size: 1363168
string(11) "close------"
[/tmp/swoole-src-2.0.6/src/factory/FactoryProcess.c:268@swFactoryProcess_finish][Worker] send: sendn=12|type=4|content=(null)
[/tmp/swoole-src-2.0.6/src/network/ReactorThread.c:307@swReactorThread_close]Close Event.fd=19|from=0
[/tmp/swoole-src-2.0.6/src/network/ReactorThread.c:350@swReactorThread_close]set_maxfd=18|close_fd=19
[/tmp/swoole-src-2.0.6/src/factory/FactoryProcess.c:268@swFactoryProcess_finish][Worker] send: sendn=189|type=0|content=HTTP/1.1 200 OK
Server: swoole-http-server
Content-Type: text/html
Connection: keep-alive
Date: Mon, 29 May 2017 14:32:18 GMT
Content-Length: 24
recv failed error : 110
[/tmp/swoole-src-2.0.6/swoole_coroutine.c:331@coro_close]closing coro and 0 remained. usage size: 1363136. malloc size: 2097152
[/tmp/swoole-src-2.0.6/src/factory/FactoryProcess.c:268@swFactoryProcess_finish][Worker] send: sendn=12|type=4|content=(null)
[/tmp/swoole-src-2.0.6/src/network/ReactorThread.c:307@swReactorThread_close]Close Event.fd=18|from=0
[/tmp/swoole-src-2.0.6/src/network/ReactorThread.c:350@swReactorThread_close]set_maxfd=17|close_fd=18
[/tmp/swoole-src-2.0.6/src/factory/FactoryProcess.c:268@swFactoryProcess_finish][Worker] send: sendn=12|type=4|content=(null)
[/tmp/swoole-src-2.0.6/src/network/ReactorThread.c:307@swReactorThread_close]Close Event.fd=17|from=0
[/tmp/swoole-src-2.0.6/src/network/ReactorThread.c:350@swReactorThread_close]set_maxfd=16|close_fd=17