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.
This commit is contained in:
Wez Furlong 2004-02-04 22:46:44 +00:00
parent 7fa5cdcb72
commit a44838e8a3
3 changed files with 11 additions and 4 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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) {