时间:2021-07-01 10:21:17 帮助过:7人阅读
$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;
php代码就是以上这样,然后我strace了一下,结果如下
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
在1572行,发送完get命令后,就调用了poll,timeout传递的是0,1573行再次调用poll,timeout变成了2000。
请问,为什么要调用两次poll呢?只调用一次可以吗?
$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;
php代码就是以上这样,然后我strace了一下,结果如下
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
在1572行,发送完get命令后,就调用了poll,timeout传递的是0,1573行再次调用poll,timeout变成了2000。
请问,为什么要调用两次poll呢?只调用一次可以吗?