$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]) = 01568 fcntl(3, F_SETFL, O_RDWR) = 01569 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 01570 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) = 421572 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) = 511575 write(1, "{\"allyid\":\"60979\",\"appid\":\"ex_mm"..., 44) = 441576 write(1, "\n", 1) = 11577 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)1578 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 01579 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) = 421581 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) = 511584 write(1, "{\"allyid\":\"60979\",\"appid\":\"ex_mm"..., 44) = 441585 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]) = 01568 fcntl(3, F_SETFL, O_RDWR) = 01569 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 01570 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) = 421572 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) = 511575 write(1, "{\"allyid\":\"60979\",\"appid\":\"ex_mm"..., 44) = 441576 write(1, "\n", 1) = 11577 poll([{fd=3, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 0 (Timeout)1578 setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 01579 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) = 421581 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) = 511584 write(1, "{\"allyid\":\"60979\",\"appid\":\"ex_mm"..., 44) = 441585 write(1, "\n", 1) = 1
在1572行,發送完get命令後,就調用了poll,timeout傳遞的是0,1573行再次調用poll,timeout變成了2000。
請問,為什麼要調用兩次poll呢?只調用一次可以嗎?