c - 为什么phpredis发送数据后要两次调用poll呢?

WBOY
发布: 2016-06-06 20:29:07
原创
1372 人浏览过

<code>$host = '127.0.0.1';
$port = 8888;

$key = 'group:32149904:binding';

$redis = new Redis();

$redis->pconnect($host, $port);

$obj = $redis->get($key);
echo $obj, PHP_EOL;</code>
登录后复制
登录后复制

php代码就是以上这样,然后我strace了一下,结果如下

<code>1565 connect(3, {sa_family=AF_INET, sin_port=htons(6080), sin_addr=inet_addr("10.83.73.168")}, 16) = -1 EINPROGRESS (Operation now in progress)
1566 poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 2000) = 1 ([{fd=3, revents=POLLOUT}])
1567 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
1568 fcntl(3, F_SETFL, O_RDWR)               = 0
1569 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
1570 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1571 sendto(3, "*2\r\n$3\r\nGET\r\n$22\r\ngroup:32149904"..., 42, MSG_DONTWAIT, NULL, 0) = 42
1572 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1573 poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 2000) = 1 ([{fd=3, revents=POLLIN}])
1574 recvfrom(3, "$44\r\n{\"allyid\":\"60979\",\"appid\":\""..., 8192, MSG_DONTWAIT, NULL, NULL) = 51
1575 write(1, "{\"allyid\":\"60979\",\"appid\":\"ex_mm"..., 44) = 44
1576 write(1, "\n", 1)                       = 1
1577 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1578 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
1579 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1580 sendto(3, "*2\r\n$3\r\nGET\r\n$22\r\ngroup:32149904"..., 42, MSG_DONTWAIT, NULL, 0) = 42
1581 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1582 poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 2000) = 1 ([{fd=3, revents=POLLIN}])
1583 recvfrom(3, "$44\r\n{\"allyid\":\"60979\",\"appid\":\""..., 8192, MSG_DONTWAIT, NULL, NULL) = 51
1584 write(1, "{\"allyid\":\"60979\",\"appid\":\"ex_mm"..., 44) = 44
1585 write(1, "\n", 1)                       = 1</code>
登录后复制
登录后复制

在1572行,发送完get命令后,就调用了poll,timeout传递的是0,1573行再次调用poll,timeout变成了2000。

请问,为什么要调用两次poll呢?只调用一次可以吗?

回复内容:

<code>$host = '127.0.0.1';
$port = 8888;

$key = 'group:32149904:binding';

$redis = new Redis();

$redis->pconnect($host, $port);

$obj = $redis->get($key);
echo $obj, PHP_EOL;</code>
登录后复制
登录后复制

php代码就是以上这样,然后我strace了一下,结果如下

<code>1565 connect(3, {sa_family=AF_INET, sin_port=htons(6080), sin_addr=inet_addr("10.83.73.168")}, 16) = -1 EINPROGRESS (Operation now in progress)
1566 poll([{fd=3, events=POLLIN|POLLOUT|POLLERR|POLLHUP}], 1, 2000) = 1 ([{fd=3, revents=POLLOUT}])
1567 getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
1568 fcntl(3, F_SETFL, O_RDWR)               = 0
1569 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
1570 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1571 sendto(3, "*2\r\n$3\r\nGET\r\n$22\r\ngroup:32149904"..., 42, MSG_DONTWAIT, NULL, 0) = 42
1572 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1573 poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 2000) = 1 ([{fd=3, revents=POLLIN}])
1574 recvfrom(3, "$44\r\n{\"allyid\":\"60979\",\"appid\":\""..., 8192, MSG_DONTWAIT, NULL, NULL) = 51
1575 write(1, "{\"allyid\":\"60979\",\"appid\":\"ex_mm"..., 44) = 44
1576 write(1, "\n", 1)                       = 1
1577 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1578 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
1579 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1580 sendto(3, "*2\r\n$3\r\nGET\r\n$22\r\ngroup:32149904"..., 42, MSG_DONTWAIT, NULL, 0) = 42
1581 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)
1582 poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 2000) = 1 ([{fd=3, revents=POLLIN}])
1583 recvfrom(3, "$44\r\n{\"allyid\":\"60979\",\"appid\":\""..., 8192, MSG_DONTWAIT, NULL, NULL) = 51
1584 write(1, "{\"allyid\":\"60979\",\"appid\":\"ex_mm"..., 44) = 44
1585 write(1, "\n", 1)                       = 1</code>
登录后复制
登录后复制

在1572行,发送完get命令后,就调用了poll,timeout传递的是0,1573行再次调用poll,timeout变成了2000。

请问,为什么要调用两次poll呢?只调用一次可以吗?

相关标签:
c php
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板