From a44838e8a3072114ba4e23486efcd219ae0c0f9c Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 4 Feb 2004 22:46:44 +0000 Subject: [PATCH] Fix a bug in the persistent socket liveness checks and feof(); they were using the default socket timeout of 60 seconds before returning the socket to the calling script. The reason they were using that value is that the same code is used for feof(), so the fix is allowing the caller to indicate the timeout value for liveness checks. A possible remaining issue now is that 0 second timeout[1] for pfsockopen is possibly too short; it's impossible to specify a sane value for all possible uses, so maybe we need a stream context or an .ini option to control this, or maybe use the timeout value that was passed to pfsockopen(). # [1] by timeout, I mean the time that PHP will wait for data on a # persistent socket before deciding if a new connection should be made; # NOT the timeout while waiting for a new connection to be established. --- main/streams/streams.c | 3 ++- main/streams/transports.c | 2 ++ main/streams/xp_socket.c | 10 +++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/main/streams/streams.c b/main/streams/streams.c index dc7a4f37ed..e3fe39d9c0 100755 --- a/main/streams/streams.c +++ b/main/streams/streams.c @@ -602,9 +602,10 @@ PHPAPI int _php_stream_eof(php_stream *stream TSRMLS_DC) return 0; } + /* use the configured timeout when checking eof */ if (!stream->eof && PHP_STREAM_OPTION_RETURN_ERR == php_stream_set_option(stream, PHP_STREAM_OPTION_CHECK_LIVENESS, - 0, NULL)) { + -1, NULL)) { stream->eof = 1; } diff --git a/main/streams/transports.c b/main/streams/transports.c index 1c20026655..04a4eccfbd 100644 --- a/main/streams/transports.c +++ b/main/streams/transports.c @@ -74,6 +74,8 @@ PHPAPI php_stream *_php_stream_xport_create(const char *name, long namelen, int if (persistent_id) { switch(php_stream_from_persistent_id(persistent_id, &stream TSRMLS_CC)) { case PHP_STREAM_PERSISTENT_SUCCESS: + /* use a 0 second timeout when checking if the socket + * has already died */ if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_CHECK_LIVENESS, 0, NULL)) { return stream; } diff --git a/main/streams/xp_socket.c b/main/streams/xp_socket.c index 00b20b2b63..d70a9c79ba 100644 --- a/main/streams/xp_socket.c +++ b/main/streams/xp_socket.c @@ -230,10 +230,14 @@ static int php_sockop_set_option(php_stream *stream, int option, int value, void char buf; int alive = 1; - if (sock->timeout.tv_sec == -1) { - tv.tv_sec = FG(default_socket_timeout); + if (value == -1) { + if (sock->timeout.tv_sec == -1) { + tv.tv_sec = FG(default_socket_timeout); + } else { + tv = sock->timeout; + } } else { - tv = sock->timeout; + tv.tv_sec = value; } if (sock->socket == -1) { -- 2.50.1