iliaa Fri Jan 19 00:02:13 2007 UTC
Modified files: (Branch: PHP_5_2)
/php-src NEWS
/php-src/ext/standard http_fopen_wrapper.c
Log:
Added read-timeout context option "timeout" for HTTP streams.
# A patch mostly by Hannes
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.500&r2=1.2027.2.547.2.501&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.500 php-src/NEWS:1.2027.2.547.2.501
--- php-src/NEWS:1.2027.2.547.2.500 Thu Jan 18 23:29:34 2007
+++ php-src/NEWS Fri Jan 19 00:02:12 2007
@@ -1,6 +1,8 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? 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)
- Improved proc_open(). Now on Windows it can run external commands not through
CMD.EXE. (Dmitry)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/http_fopen_wrapper.c?r1=1.99.2.12.2.5&r2=1.99.2.12.2.6&diff_format=u
Index: php-src/ext/standard/http_fopen_wrapper.c
diff -u php-src/ext/standard/http_fopen_wrapper.c:1.99.2.12.2.5
php-src/ext/standard/http_fopen_wrapper.c:1.99.2.12.2.6
--- php-src/ext/standard/http_fopen_wrapper.c:1.99.2.12.2.5 Sun Jan 14
14:22:40 2007
+++ php-src/ext/standard/http_fopen_wrapper.c Fri Jan 19 00:02:13 2007
@@ -19,7 +19,7 @@
| Sara Golemon <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: http_fopen_wrapper.c,v 1.99.2.12.2.5 2007/01/14 14:22:40 bjori Exp $
*/
+/* $Id: http_fopen_wrapper.c,v 1.99.2.12.2.6 2007/01/19 00:02:13 iliaa Exp $
*/
#include "php.h"
#include "php_globals.h"
@@ -104,11 +104,12 @@
int transport_len, have_header = 0, request_fulluri = 0;
char *protocol_version = NULL;
int protocol_version_len = 3; /* Default: "1.0" */
+ struct timeval timeout;
tmp_line[0] = '\0';
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;
}
@@ -159,9 +160,23 @@
}
}
+ 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_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) {
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "%s",
errstr);
@@ -232,8 +247,7 @@
redirect_max = Z_LVAL_PP(tmpzval);
}
- if (header_init && context &&
- php_stream_context_get_option(context, "http", "method",
&tmpzval) == SUCCESS) {
+ if (context && php_stream_context_get_option(context, "http", "method",
&tmpzval) == SUCCESS) {
if (Z_TYPE_PP(tmpzval) == IS_STRING && Z_STRLEN_PP(tmpzval) >
0) {
scratch_len = strlen(path) + 29 + Z_STRLEN_PP(tmpzval);
scratch = emalloc(scratch_len);
@@ -241,9 +255,8 @@
strcat(scratch, " ");
}
}
-
- if (context &&
- php_stream_context_get_option(context, "http",
"protocol_version", &tmpzval) == SUCCESS) {
+
+ if (context && php_stream_context_get_option(context, "http",
"protocol_version", &tmpzval) == SUCCESS) {
SEPARATE_ZVAL(tmpzval);
convert_to_double_ex(tmpzval);
protocol_version_len = spprintf(&protocol_version, 0, "%.1F",
Z_DVAL_PP(tmpzval));
@@ -564,7 +577,11 @@
}
}
- 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')
php_stream_notify_info(context,
PHP_STREAM_NOTIFY_REDIRECTED, location, 0);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php