[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c
kalle Tue May 19 16:02:38 2009 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c Log: Fix compiler warnings, and some unicode stuff http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.377r2=1.378diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.377 php-src/sapi/cgi/cgi_main.c:1.378 --- php-src/sapi/cgi/cgi_main.c:1.377 Tue Mar 10 23:40:02 2009 +++ php-src/sapi/cgi/cgi_main.c Tue May 19 16:02:38 2009 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.377 2009/03/10 23:40:02 helly Exp $ */ +/* $Id: cgi_main.c,v 1.378 2009/05/19 16:02:38 kalle Exp $ */ #include php.h #include php_globals.h @@ -472,7 +472,8 @@ static int sapi_cgi_read_post(char *buffer, uint count_bytes TSRMLS_DC) { - int read_bytes=0, tmp_read_bytes; + uint read_bytes = 0; + int tmp_read_bytes; count_bytes = MIN(count_bytes, (uint) SG(request_info).content_length - SG(read_post_bytes)); while (read_bytes count_bytes) { http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.54r2=1.55diff_format=u Index: php-src/sapi/cgi/fastcgi.c diff -u php-src/sapi/cgi/fastcgi.c:1.54 php-src/sapi/cgi/fastcgi.c:1.55 --- php-src/sapi/cgi/fastcgi.c:1.54 Tue Mar 10 23:40:02 2009 +++ php-src/sapi/cgi/fastcgi.c Tue May 19 16:02:38 2009 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.c,v 1.54 2009/03/10 23:40:02 helly Exp $ */ +/* $Id: fastcgi.c,v 1.55 2009/05/19 16:02:38 kalle Exp $ */ #include php.h #include fastcgi.h @@ -746,7 +746,7 @@ } else if (hdr.type == FCGI_GET_VALUES) { unsigned char *p = buf + sizeof(fcgi_header); HashPosition pos; - char * str_index; + zstr key; uint str_length; ulong num_index; int key_type; @@ -763,13 +763,13 @@ } zend_hash_internal_pointer_reset_ex(req-env, pos); - while ((key_type = zend_hash_get_current_key_ex(req-env, str_index, str_length, num_index, 0, pos)) != HASH_KEY_NON_EXISTANT) { + while ((key_type = zend_hash_get_current_key_ex(req-env, key, str_length, num_index, 0, pos)) != HASH_KEY_NON_EXISTANT) { int zlen; zend_hash_move_forward_ex(req-env, pos); if (key_type != HASH_KEY_IS_STRING) { continue; } - if (zend_hash_find(fcgi_mgmt_vars, str_index, str_length, (void**) value) != SUCCESS) { + if (zend_hash_find(fcgi_mgmt_vars, key.s, str_length, (void**) value) != SUCCESS) { continue; } --str_length; @@ -793,7 +793,7 @@ *p++ = (zlen 8) 0xff; *p++ = zlen 0xff; } - memcpy(p, str_index, str_length); + memcpy(p, key.s, str_length); p += str_length; memcpy(p, Z_STRVAL_PP(value), zlen); p += zlen; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c fastcgi.h
lbarnaudTue Oct 21 03:19:08 2008 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c fastcgi.h Log: Fixed FCGI_GET_VALUES requests (fixes #45522) http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.366r2=1.367diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.366 php-src/sapi/cgi/cgi_main.c:1.367 --- php-src/sapi/cgi/cgi_main.c:1.366 Fri Oct 17 01:34:26 2008 +++ php-src/sapi/cgi/cgi_main.c Tue Oct 21 03:19:07 2008 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.366 2008/10/17 01:34:26 iliaa Exp $ */ +/* $Id: cgi_main.c,v 1.367 2008/10/21 03:19:07 lbarnaud Exp $ */ #include php.h #include php_globals.h @@ -1619,11 +1619,18 @@ #ifndef PHP_WIN32 /* Pre-fork, if required */ if (getenv(PHP_FCGI_CHILDREN)) { - children = atoi(getenv(PHP_FCGI_CHILDREN)); + char * children_str = getenv(PHP_FCGI_CHILDREN); + children = atoi(children_str); if (children 0) { fprintf(stderr, PHP_FCGI_CHILDREN is not valid\n); return FAILURE; } + fcgi_set_mgmt_var(FCGI_MAX_CONNS, sizeof(FCGI_MAX_CONNS)-1, children_str, strlen(children_str)); + /* This is the number of concurrent requests, equals FCGI_MAX_CONNS */ + fcgi_set_mgmt_var(FCGI_MAX_REQS, sizeof(FCGI_MAX_REQS)-1, children_str, strlen(children_str)); + } else { + fcgi_set_mgmt_var(FCGI_MAX_CONNS, sizeof(FCGI_MAX_CONNS)-1, 1, sizeof(1)-1); + fcgi_set_mgmt_var(FCGI_MAX_REQS, sizeof(FCGI_MAX_REQS)-1, 1, sizeof(1)-1); } if (children) { http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.48r2=1.49diff_format=u Index: php-src/sapi/cgi/fastcgi.c diff -u php-src/sapi/cgi/fastcgi.c:1.48 php-src/sapi/cgi/fastcgi.c:1.49 --- php-src/sapi/cgi/fastcgi.c:1.48 Tue Aug 26 09:56:22 2008 +++ php-src/sapi/cgi/fastcgi.c Tue Oct 21 03:19:07 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.c,v 1.48 2008/08/26 09:56:22 dmitry Exp $ */ +/* $Id: fastcgi.c,v 1.49 2008/10/21 03:19:07 lbarnaud Exp $ */ #include php.h #include fastcgi.h @@ -133,18 +133,7 @@ struct sockaddr_in sa_inet; } sa_t; -typedef struct _fcgi_mgmt_rec { - char* name; - char name_len; - char val; -} fcgi_mgmt_rec; - -static const fcgi_mgmt_rec fcgi_mgmt_vars[] = { - {FCGI_MAX_CONNS, sizeof(FCGI_MAX_CONNS)-1, 1}, - {FCGI_MAX_REQS, sizeof(FCGI_MAX_REQS)-1, 1}, - {FCGI_MPXS_CONNS, sizeof(FCGI_MPXS_CONNS)-1, 0} -}; - +static HashTable fcgi_mgmt_vars; static int is_initialized = 0; static int is_fastcgi = 0; @@ -193,12 +182,17 @@ void fcgi_shutdown(void) { + if (is_initialized) { + zend_hash_destroy(fcgi_mgmt_vars); + } is_fastcgi = 0; } int fcgi_init(void) { if (!is_initialized) { + zend_hash_init(fcgi_mgmt_vars, 0, NULL, fcgi_free_mgmt_var_cb, 1); + fcgi_set_mgmt_var(FCGI_MPXS_CONNS, sizeof(FCGI_MPXS_CONNS)-1, 0, sizeof(0)-1); #ifdef _WIN32 # if 0 /* TODO: Support for TCP sockets */ @@ -750,8 +744,13 @@ padding = hdr.paddingLength; } } else if (hdr.type == FCGI_GET_VALUES) { - int j; unsigned char *p = buf + sizeof(fcgi_header); + HashPosition pos; + char * str_index; + uint str_length; + ulong num_index; + int key_type; + zval ** value; if (safe_read(req, buf, len+padding) != len+padding) { req-keep = 0; @@ -763,11 +762,41 @@ return 0; } - for (j = 0; j sizeof(fcgi_mgmt_vars)/sizeof(fcgi_mgmt_vars[0]); j++) { - if (zend_hash_exists(req-env, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].name_len+1) == 0) { -sprintf((char*)p, %c%c%s%c, fcgi_mgmt_vars[j].name_len, 1, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].val); -p += fcgi_mgmt_vars[j].name_len + 3; + zend_hash_internal_pointer_reset_ex(req-env, pos); + while ((key_type = zend_hash_get_current_key_ex(req-env, str_index, str_length, num_index, 0, pos)) != HASH_KEY_NON_EXISTANT) { + int zlen; + zend_hash_move_forward_ex(req-env, pos); + if (key_type != HASH_KEY_IS_STRING) { + continue; + } + if (zend_hash_find(fcgi_mgmt_vars, str_index, str_length, (void**) value) != SUCCESS) { + continue; + }
[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c fastcgi.h
dmitry Tue Aug 26 09:56:23 2008 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c fastcgi.h Log: Fixed bug #45786 (FastCGI process exited unexpectedly) http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.362r2=1.363diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.362 php-src/sapi/cgi/cgi_main.c:1.363 --- php-src/sapi/cgi/cgi_main.c:1.362 Mon Aug 18 10:48:49 2008 +++ php-src/sapi/cgi/cgi_main.c Tue Aug 26 09:56:22 2008 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.362 2008/08/18 10:48:49 dmitry Exp $ */ +/* $Id: cgi_main.c,v 1.363 2008/08/26 09:56:22 dmitry Exp $ */ #include php.h #include php_globals.h @@ -774,7 +774,7 @@ #ifndef PHP_WIN32 !parent #endif - !fcgi_finish_request((fcgi_request*)SG(server_context))) { + !fcgi_finish_request((fcgi_request*)SG(server_context), 0)) { php_handle_aborted_connection(); } } else { @@ -1921,7 +1921,7 @@ get path_translated */ if (php_request_startup(TSRMLS_C) == FAILURE) { if (fastcgi) { - fcgi_finish_request(request); + fcgi_finish_request(request, 1); } SG(server_context) = NULL; php_module_shutdown(TSRMLS_C); @@ -2064,7 +2064,7 @@ /* only fastcgi will get here */ requests++; if (max_requests (requests == max_requests)) { - fcgi_finish_request(request); + fcgi_finish_request(request, 1); if (bindpath) { free(bindpath); } http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.47r2=1.48diff_format=u Index: php-src/sapi/cgi/fastcgi.c diff -u php-src/sapi/cgi/fastcgi.c:1.47 php-src/sapi/cgi/fastcgi.c:1.48 --- php-src/sapi/cgi/fastcgi.c:1.47 Mon Aug 18 10:48:49 2008 +++ php-src/sapi/cgi/fastcgi.c Tue Aug 26 09:56:22 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.c,v 1.47 2008/08/18 10:48:49 dmitry Exp $ */ +/* $Id: fastcgi.c,v 1.48 2008/08/26 09:56:22 dmitry Exp $ */ #include php.h #include fastcgi.h @@ -662,6 +662,7 @@ unsigned char buf[FCGI_MAX_LENGTH+8]; req-keep = 0; + req-closed = 0; req-in_len = 0; req-out_hdr = NULL; req-out_pos = req-out_buf; @@ -886,7 +887,6 @@ HANDLE pipe; OVERLAPPED ov; #endif - fcgi_finish_request(req); while (1) { if (req-fd 0) { @@ -1177,13 +1177,16 @@ return len; } -int fcgi_finish_request(fcgi_request *req) +int fcgi_finish_request(fcgi_request *req, int force_close) { int ret = 1; if (req-fd = 0) { - ret = fcgi_flush(req, 1); - fcgi_close(req, 0, 1); + if (!req-closed) { + ret = fcgi_flush(req, 1); + req-closed = 1; + } + fcgi_close(req, force_close, 1); } return ret; } http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.h?r1=1.11r2=1.12diff_format=u Index: php-src/sapi/cgi/fastcgi.h diff -u php-src/sapi/cgi/fastcgi.h:1.11 php-src/sapi/cgi/fastcgi.h:1.12 --- php-src/sapi/cgi/fastcgi.h:1.11 Mon Aug 18 10:48:49 2008 +++ php-src/sapi/cgi/fastcgi.h Tue Aug 26 09:56:22 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.h,v 1.11 2008/08/18 10:48:49 dmitry Exp $ */ +/* $Id: fastcgi.h,v 1.12 2008/08/26 09:56:22 dmitry Exp $ */ /* FastCGI protocol */ @@ -99,6 +99,7 @@ intfd; intid; intkeep; + intclosed; intin_len; intin_pad; @@ -118,7 +119,7 @@ int fcgi_listen(const char *path, int backlog); void fcgi_init_request(fcgi_request *req, int listen_socket); int fcgi_accept_request(fcgi_request *req); -int fcgi_finish_request(fcgi_request *req); +int fcgi_finish_request(fcgi_request *req, int force_close); char* fcgi_getenv(fcgi_request *req, const char* var, int var_len); char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c fastcgi.h
dmitry Mon Aug 18 10:48:49 2008 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c fastcgi.h Log: Fix for bug #45786 (FastCGI process exited unexpectedly) http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.361r2=1.362diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.361 php-src/sapi/cgi/cgi_main.c:1.362 --- php-src/sapi/cgi/cgi_main.c:1.361 Fri Aug 15 07:31:07 2008 +++ php-src/sapi/cgi/cgi_main.c Mon Aug 18 10:48:49 2008 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.361 2008/08/15 07:31:07 dmitry Exp $ */ +/* $Id: cgi_main.c,v 1.362 2008/08/18 10:48:49 dmitry Exp $ */ #include php.h #include php_globals.h @@ -585,10 +585,10 @@ ulong idx; int filter_arg = (array_ptr == PG(http_globals)[TRACK_VARS_ENV])?PARSE_ENV:PARSE_SERVER; - for (zend_hash_internal_pointer_reset_ex(request-env, pos); -zend_hash_get_current_key_ex(request-env, var, var_len, idx, 0, pos) == HASH_KEY_IS_STRING -zend_hash_get_current_data_ex(request-env, (void **) val, pos) == SUCCESS; -zend_hash_move_forward_ex(request-env, pos) + for (zend_hash_internal_pointer_reset_ex(request-env, pos); +zend_hash_get_current_key_ex(request-env, var, var_len, idx, 0, pos) == HASH_KEY_IS_STRING +zend_hash_get_current_data_ex(request-env, (void **) val, pos) == SUCCESS; +zend_hash_move_forward_ex(request-env, pos) ) { unsigned int new_val_len; http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.46r2=1.47diff_format=u Index: php-src/sapi/cgi/fastcgi.c diff -u php-src/sapi/cgi/fastcgi.c:1.46 php-src/sapi/cgi/fastcgi.c:1.47 --- php-src/sapi/cgi/fastcgi.c:1.46 Tue Jul 15 13:10:42 2008 +++ php-src/sapi/cgi/fastcgi.c Mon Aug 18 10:48:49 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.c,v 1.46 2008/07/15 13:10:42 dmitry Exp $ */ +/* $Id: fastcgi.c,v 1.47 2008/08/18 10:48:49 dmitry Exp $ */ #include php.h #include fastcgi.h @@ -641,7 +641,7 @@ memcpy(tmp, p, name_len); tmp[name_len] = 0; s = estrndup((char*)p + name_len, val_len); - zend_hash_update(req-env, tmp, name_len+1, s, sizeof(char*), NULL); + zend_hash_update(req-env, tmp, name_len+1, s, sizeof(char*), NULL); p += name_len + val_len; } if (tmp != buf tmp != NULL) { @@ -665,7 +665,8 @@ req-in_len = 0; req-out_hdr = NULL; req-out_pos = req-out_buf; - zend_hash_init(req-env, 0, NULL, (void (*)(void *)) fcgi_free_var, 0); + ALLOC_HASHTABLE(req-env); + zend_hash_init(req-env, 0, NULL, (void (*)(void *)) fcgi_free_var, 0); if (safe_read(req, hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) || hdr.version FCGI_VERSION_1) { @@ -702,15 +703,15 @@ switch fcgi_begin_request*)buf)-roleB1 8) + ((fcgi_begin_request*)buf)-roleB0) { case FCGI_RESPONDER: val = estrdup(RESPONDER); - zend_hash_update(req-env, FCGI_ROLE, sizeof(FCGI_ROLE), val, sizeof(char*), NULL); + zend_hash_update(req-env, FCGI_ROLE, sizeof(FCGI_ROLE), val, sizeof(char*), NULL); break; case FCGI_AUTHORIZER: val = estrdup(AUTHORIZER); - zend_hash_update(req-env, FCGI_ROLE, sizeof(FCGI_ROLE), val, sizeof(char*), NULL); + zend_hash_update(req-env, FCGI_ROLE, sizeof(FCGI_ROLE), val, sizeof(char*), NULL); break; case FCGI_FILTER: val = estrdup(FILTER); - zend_hash_update(req-env, FCGI_ROLE, sizeof(FCGI_ROLE), val, sizeof(char*), NULL); + zend_hash_update(req-env, FCGI_ROLE, sizeof(FCGI_ROLE), val, sizeof(char*), NULL); break; default: return 0; @@ -762,7 +763,7 @@ } for (j = 0; j sizeof(fcgi_mgmt_vars)/sizeof(fcgi_mgmt_vars[0]); j++) { - if (zend_hash_exists(req-env, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].name_len+1) == 0) { + if (zend_hash_exists(req-env, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].name_len+1) == 0) { sprintf((char*)p, %c%c%s%c, fcgi_mgmt_vars[j].name_len, 1, fcgi_mgmt_vars[j].name, fcgi_mgmt_vars[j].val); p +=
[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c
dmitry Tue Jul 15 13:10:42 2008 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c Log: Fixed bug #45423 (fastcgi parent process doesn't invoke php_module_shutdown before shutdown) (basant dot kukreja at sun dot com) http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.356r2=1.357diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.356 php-src/sapi/cgi/cgi_main.c:1.357 --- php-src/sapi/cgi/cgi_main.c:1.356 Mon Jun 23 11:38:10 2008 +++ php-src/sapi/cgi/cgi_main.c Tue Jul 15 13:10:42 2008 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.356 2008/06/23 11:38:10 dmitry Exp $ */ +/* $Id: cgi_main.c,v 1.357 2008/07/15 13:10:42 dmitry Exp $ */ #include php.h #include php_globals.h @@ -101,6 +101,12 @@ */ static int parent = 1; +/* Did parent received exit signals SIG_TERM/SIG_INT/SIG_QUIT */ +static int exit_signal = 0; + +/* Is Parent waiting for children to exit */ +static int parent_waiting = 0; + /** * Process group */ @@ -1235,6 +1241,7 @@ } /* }}} */ +#ifndef PHP_WIN32 /** * Clean up child processes upon exit */ @@ -1244,16 +1251,18 @@ fprintf(stderr, FastCGI shutdown, pid %d\n, getpid()); #endif -#ifndef PHP_WIN32 sigaction(SIGTERM, old_term, 0); /* Kill all the processes in our process group */ kill(-pgroup, SIGTERM); -#endif - /* We should exit at this point, but MacOSX doesn't seem to */ - exit(0); + if (parent parent_waiting) { + exit_signal = 1; + } else { + exit(0); + } } +#endif PHP_INI_BEGIN() STD_PHP_INI_ENTRY(cgi.rfc2616_headers, 0, PHP_INI_ALL, OnUpdateBool, rfc2616_headers, php_cgi_globals_struct, php_cgi_globals) @@ -1596,7 +1605,7 @@ } if (fcgi_in_shutdown()) { - exit(0); + goto parent_out; } while (parent) { @@ -1633,9 +1642,25 @@ #ifdef DEBUG_FASTCGI fprintf(stderr, Wait for kids, pid %d\n, getpid()); #endif - while (wait(status) 0) { + parent_waiting = 1; + while (1) { + if (wait(status) = 0) { + running--; + break; + } else if (exit_signal) { + break; + } + } + if (exit_signal) { +#if 0 + while (running 0) { + while (wait(status) 0) { + } + running--; + } +#endif + goto parent_out; } - running--; } } } else { @@ -2098,6 +2123,10 @@ #endif } +#ifndef PHP_WIN32 +parent_out: +#endif + SG(server_context) = NULL; php_module_shutdown(TSRMLS_C); sapi_shutdown(); http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.45r2=1.46diff_format=u Index: php-src/sapi/cgi/fastcgi.c diff -u php-src/sapi/cgi/fastcgi.c:1.45 php-src/sapi/cgi/fastcgi.c:1.46 --- php-src/sapi/cgi/fastcgi.c:1.45 Thu Apr 3 10:25:08 2008 +++ php-src/sapi/cgi/fastcgi.c Tue Jul 15 13:10:42 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.c,v 1.45 2008/04/03 10:25:08 dmitry Exp $ */ +/* $Id: fastcgi.c,v 1.46 2008/07/15 13:10:42 dmitry Exp $ */ #include php.h #include fastcgi.h @@ -170,6 +170,20 @@ } } +static void fcgi_setup_signals(void) +{ + struct sigaction new_sa, old_sa; + + sigemptyset(new_sa.sa_mask); + new_sa.sa_flags = 0; + new_sa.sa_handler = fcgi_signal_handler; + sigaction(SIGUSR1, new_sa, NULL); + sigaction(SIGTERM, new_sa, NULL); + sigaction(SIGPIPE, NULL, old_sa); + if (old_sa.sa_handler == SIG_DFL) { + sigaction(SIGPIPE, new_sa, NULL); + } +} #endif int fcgi_in_shutdown(void) @@ -229,18 +243,7 @@ is_initialized = 1; errno = 0; if (getpeername(0, (struct sockaddr *)sa, len) != 0 errno == ENOTCONN) { - struct sigaction new_sa, old_sa; - - sigemptyset(new_sa.sa_mask); - new_sa.sa_flags = 0; - new_sa.sa_handler =
[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c
dmitry Fri Feb 15 14:51:53 2008 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c Log: optimization http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.348r2=1.349diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.348 php-src/sapi/cgi/cgi_main.c:1.349 --- php-src/sapi/cgi/cgi_main.c:1.348 Mon Dec 31 07:12:19 2007 +++ php-src/sapi/cgi/cgi_main.c Fri Feb 15 14:51:52 2008 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.348 2007/12/31 07:12:19 sebastian Exp $ */ +/* $Id: cgi_main.c,v 1.349 2008/02/15 14:51:52 dmitry Exp $ */ #include php.h #include php_globals.h @@ -754,7 +754,17 @@ 2. When the first call occurs and the request is not set up, flush fails on FastCGI. */ if (SG(sapi_started)) { - sapi_cgibin_flush(SG(server_context)); + if (fcgi_is_fastcgi()) { + if ( +#ifndef PHP_WIN32 + !parent +#endif + !fcgi_finish_request((fcgi_request*)SG(server_context))) { + php_handle_aborted_connection(); + } + } else { + sapi_cgibin_flush(SG(server_context)); + } } return SUCCESS; } http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.43r2=1.44diff_format=u Index: php-src/sapi/cgi/fastcgi.c diff -u php-src/sapi/cgi/fastcgi.c:1.43 php-src/sapi/cgi/fastcgi.c:1.44 --- php-src/sapi/cgi/fastcgi.c:1.43 Mon Dec 31 07:12:19 2007 +++ php-src/sapi/cgi/fastcgi.c Fri Feb 15 14:51:52 2008 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.c,v 1.43 2007/12/31 07:12:19 sebastian Exp $ */ +/* $Id: fastcgi.c,v 1.44 2008/02/15 14:51:52 dmitry Exp $ */ #include php.h #include fastcgi.h @@ -632,7 +632,7 @@ } memcpy(tmp, p, name_len); tmp[name_len] = 0; - s = zend_strndup((char*)p + name_len, val_len); + s = estrndup((char*)p + name_len, val_len); zend_hash_update(req-env, tmp, name_len+1, s, sizeof(char*), NULL); p += name_len + val_len; } @@ -644,7 +644,7 @@ static void fcgi_free_var(char **s) { - free(*s); + efree(*s); } static int fcgi_read_request(fcgi_request *req) @@ -657,7 +657,7 @@ req-in_len = 0; req-out_hdr = NULL; req-out_pos = req-out_buf; - zend_hash_init(req-env, 0, NULL, (void (*)(void *)) fcgi_free_var, 1); + zend_hash_init(req-env, 0, NULL, (void (*)(void *)) fcgi_free_var, 0); if (safe_read(req, hdr, sizeof(fcgi_header)) != sizeof(fcgi_header) || hdr.version FCGI_VERSION_1) { @@ -693,15 +693,15 @@ req-keep = (((fcgi_begin_request*)buf)-flags FCGI_KEEP_CONN); switch fcgi_begin_request*)buf)-roleB1 8) + ((fcgi_begin_request*)buf)-roleB0) { case FCGI_RESPONDER: - val = strdup(RESPONDER); + val = estrdup(RESPONDER); zend_hash_update(req-env, FCGI_ROLE, sizeof(FCGI_ROLE), val, sizeof(char*), NULL); break; case FCGI_AUTHORIZER: - val = strdup(AUTHORIZER); + val = estrdup(AUTHORIZER); zend_hash_update(req-env, FCGI_ROLE, sizeof(FCGI_ROLE), val, sizeof(char*), NULL); break; case FCGI_FILTER: - val = strdup(FILTER); + val = estrdup(FILTER); zend_hash_update(req-env, FCGI_ROLE, sizeof(FCGI_ROLE), val, sizeof(char*), NULL); break; default: @@ -1168,11 +1168,13 @@ int fcgi_finish_request(fcgi_request *req) { + int ret = 1; + if (req-fd = 0) { - fcgi_flush(req, 1); + ret = fcgi_flush(req, 1); fcgi_close(req, 0, 1); } - return 1; + return ret; } char* fcgi_getenv(fcgi_request *req, const char* var, int var_len) @@ -1195,7 +1197,7 @@ } else { char **ret; - val = strdup(val); + val = estrdup(val); if (zend_hash_update(req-env, var, var_len+1, val, sizeof(char*), (void**)ret) == SUCCESS) { return *ret; } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c fastcgi.h
dmitry Mon May 21 09:08:25 2007 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c fastcgi.h Log: Fixed crash on php -b 1234 -unknown-option http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.321r2=1.322diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.321 php-src/sapi/cgi/cgi_main.c:1.322 --- php-src/sapi/cgi/cgi_main.c:1.321 Tue May 15 08:17:20 2007 +++ php-src/sapi/cgi/cgi_main.c Mon May 21 09:08:25 2007 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.321 2007/05/15 08:17:20 dmitry Exp $ */ +/* $Id: cgi_main.c,v 1.322 2007/05/21 09:08:25 dmitry Exp $ */ #include php.h #include php_globals.h @@ -1369,6 +1369,7 @@ switch (c) { case 'h': case '?': + fcgi_shutdown(); no_headers = 1; php_output_tearup(); SG(headers_sent) = 1; @@ -1735,6 +1736,7 @@ } /* end of fastcgi loop */ } + fcgi_shutdown(); if (cgi_sapi_module.php_ini_path_override) { free(cgi_sapi_module.php_ini_path_override); http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.38r2=1.39diff_format=u Index: php-src/sapi/cgi/fastcgi.c diff -u php-src/sapi/cgi/fastcgi.c:1.38 php-src/sapi/cgi/fastcgi.c:1.39 --- php-src/sapi/cgi/fastcgi.c:1.38 Thu May 10 15:22:15 2007 +++ php-src/sapi/cgi/fastcgi.c Mon May 21 09:08:25 2007 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.c,v 1.38 2007/05/10 15:22:15 dmitry Exp $ */ +/* $Id: fastcgi.c,v 1.39 2007/05/21 09:08:25 dmitry Exp $ */ #include php.h #include fastcgi.h @@ -177,6 +177,11 @@ return in_shutdown; } +void fcgi_shutdown(void) +{ + is_fastcgi = 0; +} + int fcgi_init(void) { if (!is_initialized) { http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.h?r1=1.8r2=1.9diff_format=u Index: php-src/sapi/cgi/fastcgi.h diff -u php-src/sapi/cgi/fastcgi.h:1.8 php-src/sapi/cgi/fastcgi.h:1.9 --- php-src/sapi/cgi/fastcgi.h:1.8 Wed Mar 28 15:39:35 2007 +++ php-src/sapi/cgi/fastcgi.h Mon May 21 09:08:25 2007 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.h,v 1.8 2007/03/28 15:39:35 dmitry Exp $ */ +/* $Id: fastcgi.h,v 1.9 2007/05/21 09:08:25 dmitry Exp $ */ /* FastCGI protocol */ @@ -112,6 +112,7 @@ } fcgi_request; int fcgi_init(void); +void fcgi_shutdown(void); int fcgi_is_fastcgi(void); int fcgi_in_shutdown(void); int fcgi_listen(const char *path, int backlog); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c fastcgi.h
dmitry Wed Mar 28 15:39:35 2007 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c fastcgi.h Log: Improved FastCGI SAPI to support external pipe and socket servers on win32 http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.316r2=1.317diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.316 php-src/sapi/cgi/cgi_main.c:1.317 --- php-src/sapi/cgi/cgi_main.c:1.316 Fri Mar 9 16:50:17 2007 +++ php-src/sapi/cgi/cgi_main.c Wed Mar 28 15:39:35 2007 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.316 2007/03/09 16:50:17 dmitry Exp $ */ +/* $Id: cgi_main.c,v 1.317 2007/03/28 15:39:35 dmitry Exp $ */ #include php.h #include php_globals.h @@ -120,9 +120,7 @@ static const opt_struct OPTIONS[] = { {'a', 0, interactive}, -#ifndef PHP_WIN32 {'b', 1, bindpath}, -#endif {'C', 0, no-chdir}, {'c', 1, php-ini}, {'d', 1, define}, @@ -611,9 +609,7 @@ php_printf(Usage: %s [-q] [-h] [-s] [-v] [-i] [-f file]\n %s file [args...]\n -a Run interactively\n -#if !defined(PHP_WIN32) -b address:port|port Bind Path for external FASTCGI Server mode\n -#endif -C Do not chdir to the script's directory\n -c path|file Look for php.ini file in this directory\n -n No php.ini file will be used\n @@ -970,19 +966,6 @@ exit(0); } -#ifndef PHP_WIN32 -static int is_port_number(const char *bindpath) -{ - while (*bindpath) { - if (*bindpath '0' || *bindpath '9') { - return 0; - } - bindpath++; - } - return 1; -} -#endif - PHP_INI_BEGIN() STD_PHP_INI_ENTRY(cgi.rfc2616_headers, 0, PHP_INI_ALL, OnUpdateBool, rfc2616_headers, php_cgi_globals_struct, php_cgi_globals) STD_PHP_INI_ENTRY(cgi.nph, 0, PHP_INI_ALL, OnUpdateBool, nph, php_cgi_globals_struct, php_cgi_globals) @@ -1089,9 +1072,7 @@ int max_requests = 500; int requests = 0; int fastcgi = fcgi_is_fastcgi(); -#ifndef PHP_WIN32 char *bindpath = NULL; -#endif int fcgi_fd = 0; fcgi_request request; #ifndef PHP_WIN32 @@ -1152,7 +1133,6 @@ case 'n': cgi_sapi_module.php_ini_ignore = 1; break; -#ifndef PHP_WIN32 /* if we're started on command line, check to see if we are being started as an 'external' fastcgi server by accepting a bindpath parameter. */ @@ -1192,7 +1172,6 @@ bindpath = strdup(php_optarg); } break; -#endif } } @@ -1259,26 +1238,10 @@ } } -#ifndef PHP_WIN32 /* for windows, socket listening is broken in the fastcgi library itself so dissabling this feature on windows till time is available to fix it */ if (bindpath) { - /* Pass on the arg to the FastCGI library, with one exception. -* If just a port is specified, then we prepend a ':' onto the -* path (it's what the fastcgi library expects) -*/ - if (strchr(bindpath, ':') == NULL is_port_number(bindpath)) { - char *tmp; - - tmp = malloc(strlen(bindpath) + 2); - tmp[0] = ':'; - memcpy(tmp + 1, bindpath, strlen(bindpath) + 1); - - fcgi_fd = fcgi_listen(tmp, 128); - free(tmp); - } else { - fcgi_fd = fcgi_listen(bindpath, 128); - } + fcgi_fd = fcgi_listen(bindpath, 128); if (fcgi_fd 0) { fprintf(stderr, Couldn't create FastCGI listen socket on port %s\n, bindpath); #ifdef ZTS @@ -1288,7 +1251,6 @@ } fastcgi = fcgi_is_fastcgi(); } -#endif if (fastcgi) { /* How many times to run PHP scripts before dying */ if (getenv(PHP_FCGI_MAX_REQUESTS)) { @@ -1749,11 +1711,9 @@ requests++; if (max_requests (requests == max_requests)) { fcgi_finish_request(request); -#ifndef PHP_WIN32 if (bindpath) { free(bindpath); } -#endif break; }
[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c fastcgi.h
dmitry Thu Feb 15 12:33:54 2007 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c fastcgi.h Log: Fixed bug #40414 (possivle endless fork() loop when running fastcgi) http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.308r2=1.309diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.308 php-src/sapi/cgi/cgi_main.c:1.309 --- php-src/sapi/cgi/cgi_main.c:1.308 Mon Jan 29 19:38:21 2007 +++ php-src/sapi/cgi/cgi_main.c Thu Feb 15 12:33:54 2007 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: cgi_main.c,v 1.308 2007/01/29 19:38:21 dmitry Exp $ */ +/* $Id: cgi_main.c,v 1.309 2007/02/15 12:33:54 dmitry Exp $ */ #include php.h #include php_globals.h @@ -1338,6 +1338,10 @@ exit(1); } + if (fcgi_in_shutdown()) { + exit(0); + } + while (parent) { do { #ifdef DEBUG_FASTCGI http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.c?r1=1.29r2=1.30diff_format=u Index: php-src/sapi/cgi/fastcgi.c diff -u php-src/sapi/cgi/fastcgi.c:1.29 php-src/sapi/cgi/fastcgi.c:1.30 --- php-src/sapi/cgi/fastcgi.c:1.29 Thu Feb 15 12:05:25 2007 +++ php-src/sapi/cgi/fastcgi.c Thu Feb 15 12:33:54 2007 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.c,v 1.29 2007/02/15 12:05:25 dmitry Exp $ */ +/* $Id: fastcgi.c,v 1.30 2007/02/15 12:33:54 dmitry Exp $ */ #include php.h #include fastcgi.h @@ -164,6 +164,11 @@ #endif +int fcgi_in_shutdown(void) +{ + return in_shutdown; +} + int fcgi_init(void) { if (!is_initialized) { http://cvs.php.net/viewvc.cgi/php-src/sapi/cgi/fastcgi.h?r1=1.6r2=1.7diff_format=u Index: php-src/sapi/cgi/fastcgi.h diff -u php-src/sapi/cgi/fastcgi.h:1.6 php-src/sapi/cgi/fastcgi.h:1.7 --- php-src/sapi/cgi/fastcgi.h:1.6 Mon Jan 1 09:29:36 2007 +++ php-src/sapi/cgi/fastcgi.h Thu Feb 15 12:33:54 2007 @@ -16,7 +16,7 @@ +--+ */ -/* $Id: fastcgi.h,v 1.6 2007/01/01 09:29:36 sebastian Exp $ */ +/* $Id: fastcgi.h,v 1.7 2007/02/15 12:33:54 dmitry Exp $ */ /* FastCGI protocol */ @@ -110,6 +110,7 @@ int fcgi_init(void); int fcgi_is_fastcgi(void); +int fcgi_in_shutdown(void); int fcgi_listen(const char *path, int backlog); void fcgi_init_request(fcgi_request *req, int listen_socket); int fcgi_accept_request(fcgi_request *req); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /sapi/cgi cgi_main.c fastcgi.c fastcgi.h
dmitry Mon May 15 14:30:50 2006 UTC Modified files: /php-src/sapi/cgi cgi_main.c fastcgi.c fastcgi.h Log: - Removed source compatibility with libfcgi - Optimized access to FastCGI environment using HashTable instead of linear sear ch - Allowed PHP_FCGI_MAX_REQUESTS=0 to disable PHP die - Allowed PHP_FCGI_CHILDREN=0 to disable PHP spawn workers http://cvs.php.net/viewcvs.cgi/php-src/sapi/cgi/cgi_main.c?r1=1.286r2=1.287diff_format=u Index: php-src/sapi/cgi/cgi_main.c diff -u php-src/sapi/cgi/cgi_main.c:1.286 php-src/sapi/cgi/cgi_main.c:1.287 --- php-src/sapi/cgi/cgi_main.c:1.286 Wed May 3 19:40:49 2006 +++ php-src/sapi/cgi/cgi_main.c Mon May 15 14:30:50 2006 @@ -17,10 +17,11 @@ | Zeev Suraski [EMAIL PROTECTED]| | FastCGI: Ben Mansell [EMAIL PROTECTED] | | Shane Caraveo [EMAIL PROTECTED] | + | Dmitry Stogov [EMAIL PROTECTED] | +--+ */ -/* $Id: cgi_main.c,v 1.286 2006/05/03 19:40:49 tony2001 Exp $ */ +/* $Id: cgi_main.c,v 1.287 2006/05/15 14:30:50 dmitry Exp $ */ #include php.h #include php_globals.h @@ -81,9 +82,7 @@ #include fastcgi.h -#ifdef PHP_WIN32 -extern int OS_SetImpersonate(void); -#else +#ifndef PHP_WIN32 /* XXX this will need to change later when threaded fastcgi is implemented. shane */ struct sigaction act, old_term, old_quit, old_int; @@ -227,9 +226,9 @@ size_t ret; #endif - if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *) SG(server_context); - long ret = FCGX_PutStr(str, str_length, request-out); + if (fcgi_is_fastcgi()) { + fcgi_request *request = (fcgi_request*) SG(server_context); + long ret = fcgi_write(request, FCGI_STDOUT, str, str_length); if (ret = 0) { return 0; } @@ -268,13 +267,13 @@ static void sapi_cgibin_flush(void *server_context) { - if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *) server_context; + if (fcgi_is_fastcgi()) { + fcgi_request *request = (fcgi_request*) server_context; if ( #ifndef PHP_WIN32 !parent #endif - request FCGX_FFlush(request-out) == -1) { + request fcgi_flush(request, 0) == -1) { php_handle_aborted_connection(); } return; @@ -337,9 +336,9 @@ count_bytes = MIN(count_bytes, (uint) SG(request_info).content_length - SG(read_post_bytes)); while (read_bytes count_bytes) { - if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *) SG(server_context); - tmp_read_bytes = FCGX_GetStr(pos, count_bytes - read_bytes, request-in); + if (fcgi_is_fastcgi()) { + fcgi_request *request = (fcgi_request*) SG(server_context); + tmp_read_bytes = fcgi_read(request, pos, count_bytes - read_bytes); pos += tmp_read_bytes; } else { tmp_read_bytes = read(0, buffer + read_bytes, count_bytes - read_bytes); @@ -358,9 +357,9 @@ is provided to PHP. It is always sent to PHP at the start of a request. So we have to do our own lookup to get env vars. This could probably be faster somehow. */ - if (!FCGX_IsCGI()) { - FCGX_Request *request = (FCGX_Request *) SG(server_context); - return FCGX_GetParam(name,request-envp); + if (fcgi_is_fastcgi()) { + fcgi_request *request = (fcgi_request*) SG(server_context); + return fcgi_getenv(request, name, name_len); } /* if cgi, or fastcgi and not found in fcgi env check the regular environment */ @@ -369,43 +368,46 @@ static char *_sapi_cgibin_putenv(char *name, char *value TSRMLS_DC) { - int len = 0; - char *buf = NULL; + int name_len; + int len; + char *buf; + if (!name) { return NULL; } - len = strlen(name) + (value ? strlen(value) : 0) + sizeof(=) + 2; - buf = (char *) malloc(len); - if (buf == NULL) { - return getenv(name); - } - if (value) { - snprintf(buf, len - 1, %s=%s, name, value); - } else { - snprintf(buf, len - 1, %s=, name); - } + name_len = strlen(name); + /* when php is started by mod_fastcgi, no regular environment is provided to PHP. It is always sent to PHP at the start of a request. So we have to do our own lookup to get env vars. This could probably be faster somehow. */ -