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.
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;
}
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;
}
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) {