Skip to content

Commit 1423377

Browse files
committed
TCP_NODELAY for AsyncTcpConnection
1 parent 7eff149 commit 1423377

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Connection/AsyncTcpConnection.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ public function checkConnection($socket)
115115
Worker::$globalEvent->del($this->_socket, EventInterface::EV_WRITE);
116116
// Nonblocking.
117117
stream_set_blocking($this->_socket, 0);
118+
// Try to open keepalive for tcp and disable Nagle algorithm.
119+
if(function_exists('socket_import_stream'))
120+
{
121+
$raw_socket = socket_import_stream($this->_socket);
122+
socket_set_option($raw_socket, SOL_SOCKET, SO_KEEPALIVE, 1);
123+
socket_set_option($raw_socket, SOL_TCP, TCP_NODELAY, 1);
124+
}
118125
// Register a listener waiting read event.
119126
Worker::$globalEvent->add($this->_socket, EventInterface::EV_READ, array($this, 'baseRead'));
120127
// There are some data waiting to send.

0 commit comments

Comments
 (0)