mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
Added read-timeout context option "timeout" for HTTP streams.
# A patch mostly by Hannes
This commit is contained in:
parent
55eef07a71
commit
ef3fcf2894
2 changed files with 27 additions and 8 deletions
2
NEWS
2
NEWS
|
@ -1,6 +1,8 @@
|
||||||
PHP NEWS
|
PHP NEWS
|
||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
?? Jan 2007, PHP 5.2.1RC3
|
?? Jan 2007, PHP 5.2.1RC3
|
||||||
|
- Added read-timeout context option "timeout" for HTTP streams. (Hannes,
|
||||||
|
Ilia).
|
||||||
- Added CURLOPT_TCP_NODELAY constant to Curl extension. (Sara)
|
- Added CURLOPT_TCP_NODELAY constant to Curl extension. (Sara)
|
||||||
- Improved proc_open(). Now on Windows it can run external commands not through
|
- Improved proc_open(). Now on Windows it can run external commands not through
|
||||||
CMD.EXE. (Dmitry)
|
CMD.EXE. (Dmitry)
|
||||||
|
|
|
@ -104,11 +104,12 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
|
||||||
int transport_len, have_header = 0, request_fulluri = 0;
|
int transport_len, have_header = 0, request_fulluri = 0;
|
||||||
char *protocol_version = NULL;
|
char *protocol_version = NULL;
|
||||||
int protocol_version_len = 3; /* Default: "1.0" */
|
int protocol_version_len = 3; /* Default: "1.0" */
|
||||||
|
struct timeval timeout;
|
||||||
|
|
||||||
tmp_line[0] = '\0';
|
tmp_line[0] = '\0';
|
||||||
|
|
||||||
if (redirect_max < 1) {
|
if (redirect_max < 1) {
|
||||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Redirection limit reached, aborting.");
|
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "Redirection limit reached, aborting");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,9 +160,23 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context && php_stream_context_get_option(context, wrapper->wops->label, "timeout", &tmpzval) == SUCCESS) {
|
||||||
|
SEPARATE_ZVAL(tmpzval);
|
||||||
|
convert_to_double_ex(tmpzval);
|
||||||
|
timeout.tv_sec = (time_t) Z_DVAL_PP(tmpzval);
|
||||||
|
timeout.tv_usec = (suseconds_t) ((Z_DVAL_PP(tmpzval) - timeout.tv_sec) * 1000000);
|
||||||
|
} else {
|
||||||
|
timeout.tv_sec = FG(default_socket_timeout);
|
||||||
|
timeout.tv_usec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
stream = php_stream_xport_create(transport_string, transport_len, options,
|
stream = php_stream_xport_create(transport_string, transport_len, options,
|
||||||
STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT,
|
STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT,
|
||||||
NULL, NULL, context, &errstr, NULL);
|
NULL, &timeout, context, &errstr, NULL);
|
||||||
|
|
||||||
|
if (stream) {
|
||||||
|
php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &timeout);
|
||||||
|
}
|
||||||
|
|
||||||
if (errstr) {
|
if (errstr) {
|
||||||
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s", errstr);
|
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s", errstr);
|
||||||
|
@ -232,8 +247,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
|
||||||
redirect_max = Z_LVAL_PP(tmpzval);
|
redirect_max = Z_LVAL_PP(tmpzval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header_init && context &&
|
if (context && php_stream_context_get_option(context, "http", "method", &tmpzval) == SUCCESS) {
|
||||||
php_stream_context_get_option(context, "http", "method", &tmpzval) == SUCCESS) {
|
|
||||||
if (Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval) > 0) {
|
if (Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval) > 0) {
|
||||||
scratch_len = strlen(path) + 29 + Z_STRLEN_PP(tmpzval);
|
scratch_len = strlen(path) + 29 + Z_STRLEN_PP(tmpzval);
|
||||||
scratch = emalloc(scratch_len);
|
scratch = emalloc(scratch_len);
|
||||||
|
@ -242,8 +256,7 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context &&
|
if (context && php_stream_context_get_option(context, "http", "protocol_version", &tmpzval) == SUCCESS) {
|
||||||
php_stream_context_get_option(context, "http", "protocol_version", &tmpzval) == SUCCESS) {
|
|
||||||
SEPARATE_ZVAL(tmpzval);
|
SEPARATE_ZVAL(tmpzval);
|
||||||
convert_to_double_ex(tmpzval);
|
convert_to_double_ex(tmpzval);
|
||||||
protocol_version_len = spprintf(&protocol_version, 0, "%.1F", Z_DVAL_PP(tmpzval));
|
protocol_version_len = spprintf(&protocol_version, 0, "%.1F", Z_DVAL_PP(tmpzval));
|
||||||
|
@ -564,7 +577,11 @@ php_stream *php_stream_url_wrap_http_ex(php_stream_wrapper *wrapper, char *path,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reqok || location[0] != '\0') {
|
if (!reqok || location[0] != '\0') {
|
||||||
|
if (options & STREAM_ONLY_GET_HEADERS && redirect_max <= 1) {
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (location[0] != '\0')
|
if (location[0] != '\0')
|
||||||
php_stream_notify_info(context, PHP_STREAM_NOTIFY_REDIRECTED, location, 0);
|
php_stream_notify_info(context, PHP_STREAM_NOTIFY_REDIRECTED, location, 0);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue