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

WBOY
Lepaskan: 2016-06-06 20:29:07
asal
1372 orang telah melayarinya

<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>
Salin selepas log masuk
Salin selepas log masuk

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>
Salin selepas log masuk
Salin selepas log masuk

在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>
Salin selepas log masuk
Salin selepas log masuk

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>
Salin selepas log masuk
Salin selepas log masuk

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

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

Label berkaitan:
c php
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan