Implement a default_socket_timeout and auto_detect_line_endings ini options.

Also move user_agent from BG to FG.
This commit is contained in:
Wez Furlong 2002-09-23 18:12:39 +00:00
parent 8dde690042
commit c74b9faca5
8 changed files with 35 additions and 11 deletions

View File

@ -141,9 +141,6 @@ typedef struct {
HashTable sm_protected_env_vars;
char *sm_allowed_env_vars;
/* file.c */
char *user_agent;
/* pageinfo.c */
long page_uid;

View File

@ -157,7 +157,9 @@ static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC)
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateString, user_agent, php_basic_globals, basic_globals)
STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateString, user_agent, php_file_globals, file_globals)
STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateInt, default_socket_timeout, php_file_globals, file_globals)
STD_PHP_INI_ENTRY("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateInt, auto_detect_line_endings, php_file_globals, file_globals)
PHP_INI_END()
PHP_MINIT_FUNCTION(file)

View File

@ -115,6 +115,9 @@ typedef struct {
int pclose_ret;
HashTable ht_persistent_socks;
size_t def_chunk_size;
int auto_detect_line_endings;
int default_socket_timeout;
char *user_agent;
} php_file_globals;
#ifdef ZTS

View File

@ -203,8 +203,8 @@ php_stream *php_stream_url_wrap_http(php_stream_wrapper *wrapper, char *path, ch
if (context &&
php_stream_context_get_option(context, "http", "user_agent", &ua_zval) == SUCCESS) {
ua_str = Z_STRVAL_PP(ua_zval);
} else if (BG(user_agent)) {
ua_str = BG(user_agent);
} else if (FG(user_agent)) {
ua_str = FG(user_agent);
}
if (ua_str) {

View File

@ -19,8 +19,6 @@
/* $Id$ */
/*#define DEBUG_MAIN_NETWORK 1*/
#define MAX_CHUNKS_PER_READ 10
#define SOCKET_DEFAULT_TIMEOUT 60
#include "php.h"
@ -540,7 +538,7 @@ PHPAPI php_stream *_php_stream_sock_open_from_socket(int socket, int persistent
memset(sock, 0, sizeof(php_netstream_data_t));
sock->is_blocked = 1;
sock->timeout.tv_sec = SOCKET_DEFAULT_TIMEOUT;
sock->timeout.tv_sec = FG(default_socket_timeout);
sock->socket = socket;
stream = php_stream_alloc_rel(&php_stream_socket_ops, sock, persistent, "r+");

View File

@ -95,6 +95,10 @@ fprintf(stderr, "stream_alloc: %s:%p\n", ops->label, ret);
ret->abstract = abstract;
ret->is_persistent = persistent;
ret->chunk_size = FG(def_chunk_size);
if (FG(auto_detect_line_endings))
ret->flags |= PHP_STREAM_FLAG_DETECT_EOL;
ret->rsrc_id = ZEND_REGISTER_RESOURCE(NULL, ret, php_file_le_stream());
strlcpy(ret->mode, mode, sizeof(ret->mode));
@ -514,7 +518,7 @@ PHPAPI char *_php_stream_gets(php_stream *stream, char *buf, size_t maxlen TSRML
eol = memchr(readptr, '\n', avail);
}
if (eol && ((ptrdiff_t)eol + 1 - (ptrdiff_t)readptr) <= maxlen - 1) {
if (eol && (size_t)((ptrdiff_t)eol + 1 - (ptrdiff_t)readptr) <= maxlen - 1) {
justread = eol + 1 - readptr;
} else {
eol = NULL;

View File

@ -215,7 +215,6 @@ expose_php = On
max_execution_time = 30 ; Maximum execution time of each script, in seconds
memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Error handling and logging ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -469,6 +468,16 @@ allow_url_fopen = On
; Define the User-Agent string
; user_agent="PHP"
; Default timeout for socket based streams (seconds)
default_socket_timeout = 60
; If your scripts have to deal with files from Macintosh systems,
; or you are running on a Mac and need to deal with files from
; unix or win32 systems, setting this flag will cause PHP to
; automatically detect the EOL character in those files so that
; fgets() and file() will work regardless of the source of the file.
; auto_detect_line_endings = Off
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;

View File

@ -483,6 +483,17 @@ allow_url_fopen = On
; Define the user agent for php to send
;user_agent="PHP"
; Default timeout for socket based streams (seconds)
default_socket_timeout = 60
; If your scripts have to deal with files from Macintosh systems,
; or you are running on a Mac and need to deal with files from
; unix or win32 systems, setting this flag will cause PHP to
; automatically detect the EOL character in those files so that
; fgets() and file() will work regardless of the source of the file.
; auto_detect_line_endings = Off
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;