Here's an incremental patch on Lukas' patch which tries to address a
couple issues:
o The startup sequence has been changed to allow for post-data to make
it through if any hooks before full post-data is read are called
o works under register_globals Off ($request is now available in the
SERVER var hash when register globals is enabled)
o all hooks and the 'main' content handler all share a common scope
(there is only one call to zend_startup, and only one shutdown). This
is significantly cheaper plus it allows for handy stuff like creating
data structures in a hook and magicall passing them to other hooks or
into the main script. This is experimental and may break some of the
other sapi modules as-is (though that clearly wasn't the intention ;)
George
Lukas Schroeder wrote:
>hi,
>
>here's another shot of the current apache_hooks code.
>
>there are some issues with startup and cleanup currently.
>and the patch messes a bit with php's startup procedure.
>
>still missing is access to array_header (think headers_in, headers_out,
>headers_err) and table slot in request_rec, as is access to the
>whole connection structure of the request.
>
>but the string and int fields can be read and where appropriate written
>to. and there are some methods that wrap the ap_ family.
>
>
>
>regards,
> -lukas
>
diff -u3 -r php4-lucas3/main/SAPI.c php4-george/main/SAPI.c
--- php4-lucas3/main/SAPI.c Mon Aug 26 11:44:12 2002
+++ php4-george/main/SAPI.c Mon Aug 26 12:05:51 2002
@@ -382,6 +382,7 @@
SG(sapi_headers).mimetype = NULL;
}
sapi_send_headers_free(TSRMLS_C);
+ SG(sapi_started) = 0;
}
diff -u3 -r php4-lucas3/main/SAPI.h php4-george/main/SAPI.h
--- php4-lucas3/main/SAPI.h Mon Aug 26 11:44:12 2002
+++ php4-george/main/SAPI.h Mon Aug 26 12:04:04 2002
@@ -117,6 +117,7 @@
HashTable *rfc1867_uploaded_files;
long post_max_size;
int options;
+ zend_bool sapi_started;
} sapi_globals_struct;
diff -u3 -r php4-lucas3/main/main.c php4-george/main/main.c
--- php4-lucas3/main/main.c Mon Aug 26 11:45:03 2002
+++ php4-george/main/main.c Mon Aug 26 12:42:10 2002
@@ -816,54 +816,52 @@
/* {{{ php_request_startup
*/
int php_request_startup(TSRMLS_D)
-{
- int retval = SUCCESS;
-
+{
+ int retval = SUCCESS;
#if PHP_SIGCHILD
- signal(SIGCHLD, sigchld_handler);
-#endif
-
- zend_try {
- PG(during_request_startup) = 1;
-
- php_output_activate(TSRMLS_C);
-
- /* initialize global variables */
- PG(modules_activated) = 0;
- PG(header_is_being_sent) = 0;
- PG(connection_status) = PHP_CONNECTION_NORMAL;
-
- zend_activate(TSRMLS_C);
- sapi_activate(TSRMLS_C);
-
- zend_set_timeout(EG(timeout_seconds));
-
- if (PG(expose_php)) {
- sapi_add_header(SAPI_PHP_VERSION_HEADER,
sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
- }
-
- if (PG(output_handler) && PG(output_handler)[0]) {
- php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC);
- }
- else if (PG(output_buffering)) {
- php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
- }
- else if (PG(implicit_flush)) {
- php_start_implicit_flush(TSRMLS_C);
- }
-
- /* We turn this off in php_execute_script() */
- /* PG(during_request_startup) = 0; */
-
- php_hash_environment(TSRMLS_C);
- zend_activate_modules(TSRMLS_C);
- PG(modules_activated)=1;
- } zend_catch {
- retval = FAILURE;
- } zend_end_try();
+ signal(SIGCHLD, sigchld_handler);
+#endif
+ if(!SG(sapi_started)) {
+ zend_try {
+ PG(during_request_startup) = 1;
+
+ /* initialize global variables */
+ PG(modules_activated) = 0;
+ PG(header_is_being_sent) = 0;
+ PG(connection_status) = PHP_CONNECTION_NORMAL;
+
+ zend_activate(TSRMLS_C);
+ zend_set_timeout(EG(timeout_seconds));
+ zend_activate_modules(TSRMLS_C);
+ PG(modules_activated)=1;
+ } zend_catch {
+ retval = FAILURE;
+ } zend_end_try();
+ SG(sapi_started) = 1;
+ }
+ php_output_activate(TSRMLS_C);
+ sapi_activate(TSRMLS_C);
+ php_hash_environment(TSRMLS_C);
+ zend_try {
+ if (PG(expose_php)) {
+ sapi_add_header(SAPI_PHP_VERSION_HEADER,
+sizeof(SAPI_PHP_VERSION_HEADER)-1, 1);
+ }
+ if (PG(output_handler) && PG(output_handler)[0]) {
+ php_start_ob_buffer_named(PG(output_handler), 0, 1 TSRMLS_CC);
+ }
+ else if (PG(output_buffering)) {
+ php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC);
+ }
+ else if (PG(implicit_flush)) {
+ php_start_implicit_flush(TSRMLS_C);
+ }
+ } zend_catch {
+ retval = FAILURE;
+ } zend_end_try();
- return retval;
+ return retval;
}
+
/* }}} */
/* {{{ php_request_startup_for_hook
@@ -871,25 +869,26 @@
int php_request_startup_for_hook(TSRMLS_D)
{
int retval = SUCCESS;
-
#if PHP_SIGCHLD
signal(SIGCHLD, sigchld_handler);
#endif
-
- zend_try {
- PG(during_request_startup) = 1;
- PG(modules_activated) = 0;
- PG(header_is_being_sent) = 0;
- PG(connection_status) = PHP_CONNECTION_NORMAL;
- zend_activate(TSRMLS_C);
- sapi_activate(TSRMLS_C);
- zend_set_timeout(EG(timeout_seconds));
- php_hash_environment(TSRMLS_C);
- zend_activate_modules(TSRMLS_C);
- PG(modules_activated) = 1;
- } zend_catch {
- retval = FAILURE;
- } zend_end_try();
+ if(!SG(sapi_started)) {
+ zend_try {
+ PG(during_request_startup) = 1;
+ PG(modules_activated) = 0;
+ PG(header_is_being_sent) = 0;
+ PG(connection_status) = PHP_CONNECTION_NORMAL;
+ zend_activate(TSRMLS_C);
+ zend_activate_modules(TSRMLS_C);
+ PG(modules_activated) = 1;
+ } zend_catch {
+ retval = FAILURE;
+ } zend_end_try();
+ SG(sapi_started) = 1;
+ }
+ sapi_activate(TSRMLS_C);
+ zend_set_timeout(EG(timeout_seconds));
+ php_hash_environment(TSRMLS_C);
return retval;
}
@@ -912,7 +911,6 @@
void php_request_shutdown_for_hook(void *dummy)
{
TSRMLS_FETCH();
-
if (PG(modules_activated)) zend_try {
php_call_shutdown_functions();
} zend_end_try();
diff -u3 -r php4-lucas3/sapi/apache/mod_php4.c php4-george/sapi/apache/mod_php4.c
--- php4-lucas3/sapi/apache/mod_php4.c Mon Aug 26 11:45:03 2002
+++ php4-george/sapi/apache/mod_php4.c Mon Aug 26 12:41:40 2002
@@ -290,13 +290,13 @@
static void php_apache_request_shutdown(void *dummy)
{
TSRMLS_FETCH();
-
php_output_set_status(0 TSRMLS_CC);
SG(server_context) = NULL; /* The server context (request) is invalid by the
time run_cleanups() is called */
- if (AP(in_request)) {
- AP(in_request) = 0;
+ if(SG(sapi_started)) {
php_request_shutdown(dummy);
+ SG(sapi_started) = 0;
}
+ AP(in_request) = 0;
if(AP(setup_env)) {
AP(setup_env) = 0;
}
diff -u3 -r php4-lucas3/sapi/apache/sapi_apache.c php4-george/sapi/apache/sapi_apache.c
--- php4-lucas3/sapi/apache/sapi_apache.c Mon Aug 26 11:45:03 2002
+++ php4-george/sapi/apache/sapi_apache.c Mon Aug 26 11:49:02 2002
@@ -57,10 +57,6 @@
AP(in_request) = 0;
- zend_try {
- php_request_shutdown(NULL);
- } zend_end_try();
-
return (OK);
}
/* }}} */
@@ -76,20 +72,20 @@
signal(SIGCHLD, sigchld_handler);
#endif
- if (AP(setup_env) != 2) {
- fprintf(stderr, "REQUEST STARTUP\n");
+ if (php_request_startup_for_hook(TSRMLS_C) == FAILURE)
+ return FAILURE;
- if (php_request_startup(TSRMLS_C) == FAILURE)
- return FAILURE;
- AP(setup_env) = 2;
- }
/* Add PHP_SELF_HOOK - Absolute path */
php_register_variable("PHP_SELF_HOOK", filename,
PG(http_globals)[TRACK_VARS_SERVER] TSRMLS_CC);
req = php_apache_request_new(r);
- php_register_variable_ex("request", req, NULL TSRMLS_CC);
-
+ if(PG(register_globals)) {
+ php_register_variable_ex("request", req, NULL TSRMLS_CC);
+ }
+ else {
+ php_register_variable_ex("request", req, PG(http_globals)[TRACK_VARS_SERVER]
+TSRMLS_CC);
+ }
memset(&file_handle, 0, sizeof(file_handle));
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.filename = filename;
@@ -98,10 +94,6 @@
zval_dtor(&req);
AP(in_request) = 0;
-
-// zend_try {
-// php_request_shutdown_for_hook(NULL);
-// } zend_end_try();
return OK;
}
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php