php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46360 [PATCH] TCP_NODELAY constant for socket_{get,set}_option
Submitted: 2008-10-22 04:44 UTC Modified: 2009-08-10 04:42 UTC
From: bugs at trick dot vanstaveren dot us Assigned:
Status: Closed Package: Sockets related
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
 [2008-10-22 04:44 UTC] bugs at trick dot vanstaveren dot us
Description:
------------
C-level TCP function setsockopt allows users of TCP sockets to set the TCP_NODELAY flag.  This flag disable's the typically default use of Nagle's Algorithm[1] on a TCP socket.

1: http://en.wikipedia.org/wiki/Nagle%27s_algorithm

Nagle's Algorithm is bad for protocols like the extremely brief one spoken by PHP/Java Bridge.  This patch is inspired by my use of PJB on FreeBSD which does not automatically set TCP_NODELAY on localhost connections.

PHP does not expose this constant, although it is valid for the sockets library as socket_set_option is a straightforward wrapper around setsockopt.

Here is a trivial patch against PHP 5.2.5 to add the PHP constant TCP_NODELAY.  I have tested this on FreeBSD 7.0 + PHP 5.2.5.  Patch is quite simple so should apply fine against 5.3 / 6 with just a line offset.  Constant is the same on Linux so will work fine there; am not sure about win32.  Happy to test other versions and platforms if necessary.

--- ext/sockets/sockets.c.orig	2008-10-21 22:53:07.000000000 +0000
+++ ext/sockets/sockets.c	2008-10-21 22:53:00.000000000 +0000
@@ -509,6 +509,7 @@
 	REGISTER_LONG_CONSTANT("SO_ERROR",		SO_ERROR,		CONST_CS | CONST_PERSISTENT);
 	REGISTER_LONG_CONSTANT("SOL_SOCKET",	SOL_SOCKET,		CONST_CS | CONST_PERSISTENT);
 	REGISTER_LONG_CONSTANT("SOMAXCONN",		SOMAXCONN,		CONST_CS | CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("TCP_NODELAY",   TCP_NODELAY,	CONST_CS | CONST_PERSISTENT);
 	REGISTER_LONG_CONSTANT("PHP_NORMAL_READ", PHP_NORMAL_READ, CONST_CS | CONST_PERSISTENT);
 	REGISTER_LONG_CONSTANT("PHP_BINARY_READ", PHP_BINARY_READ, CONST_CS | CONST_PERSISTENT);

Cheers,
Patrick van Staveren


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-10-22 11:14 UTC] felipe@php.net
It exists on Windows, according to http://msdn.microsoft.com/en-us/library/ms740476(VS.85).aspx
 [2008-10-22 19:00 UTC] lbarnaud@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2008-10-23 21:31 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

http://news.php.net/php.cvs/53681
 [2008-10-28 21:06 UTC] bugs at trick dot vanstaveren dot us
Thanks for accepting this so quickly :)  Fortunate timing on my part that this will make it into 5.2.7

I wouldn't mind doing the documentation bit as I've been wanting to learn how the PHP documentation is built and thus how I can supply patches.  I've been writing PHP day in and day out for the last two years, so I live on the PHP manual.

I'm going to give the Documentation HOWTO a read in the near future; if anyone has any pointers beyond that, feel free to throw them my way.
 [2009-08-10 04:42 UTC] bugs at trick dot vanstaveren dot us
Was documented in r277584; thanks didou.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC