diff options
Diffstat (limited to 'sapi/fastcgi/fastcgi.c')
| -rw-r--r-- | sapi/fastcgi/fastcgi.c | 50 |
1 files changed, 44 insertions, 6 deletions
diff --git a/sapi/fastcgi/fastcgi.c b/sapi/fastcgi/fastcgi.c index 80b5c3c204..2779484999 100644 --- a/sapi/fastcgi/fastcgi.c +++ b/sapi/fastcgi/fastcgi.c @@ -17,7 +17,7 @@ */ /* Debugging */ -/* #define DEBUG_FASTCGI 1 */ +/* #define DEBUG_FASTCGI 1 */ /* Two configurables for the FastCGI runner. * @@ -49,7 +49,11 @@ #if HAVE_UNISTD_H #include <unistd.h> #endif -#ifndef PHP_WIN32 +#ifdef PHP_WIN32 +#include <io.h> +#include <fcntl.h> +#include "win32/php_registry.h" +#else #include <sys/wait.h> #endif #include <sys/stat.h> @@ -226,7 +230,7 @@ static void fastcgi_module_main(TSRMLS_D) } -static void init_request_info( TSRMLS_D ) +static int init_request_info( TSRMLS_D ) { char *content_length = getenv("CONTENT_LENGTH"); char *content_type = getenv( "CONTENT_TYPE" ); @@ -250,7 +254,7 @@ static void init_request_info( TSRMLS_D ) SG(sapi_headers).http_response_code = 200; SG(request_info).path_translated = pt; - if (!pt) return; + if (!pt) return -1; /* * if the file doesn't exist, try to extract PATH_INFO out * of it by stat'ing back through the '/' @@ -292,12 +296,13 @@ static void init_request_info( TSRMLS_D ) #endif php_handle_auth_data(auth TSRMLS_CC); - + return 0; } void fastcgi_php_init(void) { + TSRMLS_FETCH(); sapi_startup(&fastcgi_sapi_module); fastcgi_sapi_module.startup(&fastcgi_sapi_module); SG(server_context) = (void *) 1; @@ -305,6 +310,7 @@ void fastcgi_php_init(void) void fastcgi_php_shutdown(void) { + TSRMLS_FETCH(); if (SG(server_context) != NULL) { fastcgi_sapi_module.shutdown(&fastcgi_sapi_module); sapi_shutdown(); @@ -349,6 +355,13 @@ int main(int argc, char *argv[]) int max_requests = 500; int requests = 0; int env_size, cgi_env_size; +#ifdef ZTS + zend_compiler_globals *compiler_globals; + zend_executor_globals *executor_globals; + php_core_globals *core_globals; + sapi_globals_struct *sapi_globals; + void ***tsrm_ls; +#endif #ifdef DEBUG_FASTCGI fprintf( stderr, "Initialising now, pid %d!\n", getpid() ); @@ -385,11 +398,27 @@ int main(int argc, char *argv[]) #endif #endif +#ifdef ZTS + tsrm_startup(1, 1, 0, NULL); +#endif sapi_startup(&fastcgi_sapi_module); +#ifdef PHP_WIN32 + _fmode = _O_BINARY; /*sets default for file streams to binary */ + setmode(_fileno(stdin), O_BINARY); /* make the stdio mode be binary */ + setmode(_fileno(stdout), O_BINARY); /* make the stdio mode be binary */ + setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */ +#endif if (php_module_startup(&fastcgi_sapi_module)==FAILURE) { return FAILURE; } +#ifdef ZTS + compiler_globals = ts_resource(compiler_globals_id); + executor_globals = ts_resource(executor_globals_id); + core_globals = ts_resource(core_globals_id); + sapi_globals = ts_resource(sapi_globals_id); + tsrm_ls = ts_resource(0); +#endif /* How many times to run PHP scripts before dying */ if( getenv( "PHP_FCGI_MAX_REQUESTS" )) { @@ -501,7 +530,13 @@ int main(int argc, char *argv[]) cgi_env, (cgi_env_size+1)*sizeof(char *) ); environ = merge_env; - init_request_info(TSRMLS_C); + if (init_request_info(TSRMLS_C)!=0) { + /* we received some invalid environment */ + //char *b = "Can't init the request\n"; + //sapi_fastcgi_ub_write(b, strlen(b) TSRMLS_C); + //FCGX_Finish(); + //break; + } SG(server_context) = (void *) 1; /* avoid server_context==NULL checks */ CG(extended_info) = 0; SG(request_info).argv0 = argv0; @@ -526,6 +561,9 @@ int main(int argc, char *argv[]) } } +#ifdef ZTS + tsrm_shutdown(); +#endif #ifdef DEBUG_FASTCGI fprintf( stderr, "Exiting...\n" ); #endif |
