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

WBOY
Release: 2016-06-06 20:29:07
Original
1371 people have browsed it

<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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

在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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

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

Related labels:
c php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template