[PHP-CVS] svn: /php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/ fastcgi.c

2009-12-23 Thread Antony Dovgal
tony2001 Wed, 23 Dec 2009 09:42:47 +

Revision: http://svn.php.net/viewvc?view=revision&revision=292520

Log:
fix leak (merge from trunk)

Changed paths:
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c

Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c
===
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c 2009-12-23 
09:40:28 UTC (rev 292519)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c 2009-12-23 
09:42:47 UTC (rev 292520)
@@ -273,6 +273,9 @@
zend_hash_destroy(&fcgi_mgmt_vars);
}
is_fastcgi = 0;
+   if (allowed_clients) {
+   free(allowed_clients);
+   }
 }

 #ifdef _WIN32

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-CVS] svn: /php/php-src/branches/PHP_5_3_FPM/sapi/fpm/ fpm/fastcgi.c fpm/fpm_children.c fpm/fpm_children.h fpm/fpm_conf.c fpm/fpm_conf.h fpm/fpm_config.h fpm/fpm_events.c fpm/fpm_process_ctl.c fpm

2009-12-14 Thread Antony Dovgal
tony2001 Mon, 14 Dec 2009 14:02:34 +

Revision: http://svn.php.net/viewvc?view=revision&revision=292133

Log:
add experimental dynamic process spawning support (patch by Jerome Loyet)

Changed paths:
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_children.c
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_children.h
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_conf.c
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_conf.h
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_config.h
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_events.c
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_process_ctl.c
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_process_ctl.h
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_request.c
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_request.h
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_worker_pool.c
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_worker_pool.h
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/php-fpm.conf.in

Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c
===
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c	2009-12-14 13:50:21 UTC (rev 292132)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c	2009-12-14 14:02:34 UTC (rev 292133)
@@ -986,13 +986,13 @@
 		int n = 0;
 		int allowed = 0;

-			while (allowed_clients[n] != INADDR_NONE) {
-if (allowed_clients[n] == sa.sa_inet.sin_addr.s_addr) {
-	allowed = 1;
-	break;
-}
-n++;
+		while (allowed_clients[n] != INADDR_NONE) {
+			if (allowed_clients[n] == sa.sa_inet.sin_addr.s_addr) {
+allowed = 1;
+break;
 			}
+			n++;
+		}
 		if (!allowed) {
 			fprintf(stderr, "Connection from disallowed IP address '%s' is dropped.\n", inet_ntoa(sa.sa_inet.sin_addr));
 			closesocket(req->fd);

Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_children.c
===
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_children.c	2009-12-14 13:50:21 UTC (rev 292132)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_children.c	2009-12-14 14:02:34 UTC (rev 292133)
@@ -32,8 +32,6 @@
 static time_t *last_faults;
 static int fault;

-static int fpm_children_make(struct fpm_worker_pool_s *wp, int in_event_loop);
-
 static void fpm_children_cleanup(int which, void *arg) /* {{{ */
 {
 	free(last_faults);
@@ -180,6 +178,7 @@
 	while ( (pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) {
 		char buf[128];
 		int severity = ZLOG_NOTICE;
+		int restart_child = 1;

 		child = fpm_child_find(pid);

@@ -187,6 +186,13 @@

 			snprintf(buf, sizeof(buf), "with code %d", WEXITSTATUS(status));

+			/* if it's been killed because of dynamic process management
+			 * don't restart it automaticaly
+			 */
+			if (child && child->idle_kill) {
+restart_child = 0;
+			}
+
 			if (WEXITSTATUS(status) != 0) {
 severity = ZLOG_WARNING;
 			}
@@ -201,6 +207,13 @@

 			snprintf(buf, sizeof(buf), "on signal %d %s%s", WTERMSIG(status), signame, have_core);

+			/* if it's been killed because of dynamic process management
+			 * don't restart it automaticaly
+			 */
+			if (child && child->idle_kill && WTERMSIG(status) == SIGTERM) {
+restart_child = 0;
+			}
+
 			if (WTERMSIG(status) != SIGQUIT) { /* possible request loss */
 severity = ZLOG_WARNING;
 			}
@@ -227,8 +240,11 @@

 			timersub(&tv1, &child->started, &tv2);

-			zlog(ZLOG_STUFF, severity, "child %d (pool %s) exited %s after %ld.%06d seconds from start", (int) pid,
-		child->wp->config->name, buf, tv2.tv_sec, (int) tv2.tv_usec);
+			if (restart_child) {
+zlog(ZLOG_STUFF, severity, "child %d (pool %s) exited %s after %ld.%06d seconds from start", (int) pid, child->wp->config->name, buf, tv2.tv_sec, (int) tv2.tv_usec);
+			} else {
+zlog(ZLOG_STUFF, severity, "child %d (pool %s) has been killed by the process managment after %ld.%06d seconds from start", (int) pid, child->wp->config->name, tv2.tv_sec, (int) tv2.tv_usec);
+			}

 			fpm_child_close(child, 1 /* in event_loop */);

@@ -254,17 +270,18 @@

 if (restart_condition) {

-	zlog(ZLOG_STUFF, ZLOG_WARNING, "failed processes threshold (%d in %d sec) is reached, initiating reload",
-		fpm_global_config.emergency_restart_threshold, fpm_global_config.emergency_restart_interval);
+	zlog(ZLOG_STUFF, ZLOG_WARNING, "failed processes threshold (%d in %d sec) is reached, initiating reload", fpm_global_config.emergency_restart_threshold, fpm_global_config.emergency_restart_interval);

 	fpm_pctl(FPM_PCTL_STATE_RELOADING, FPM_PCTL_ACTION_SET);
 }
 			}

-			fpm_children_make(wp, 1 /* in event loop */);
+			if (restart_ch

[PHP-CVS] svn: /php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/ fastcgi.c

2009-12-08 Thread Antony Dovgal
tony2001 Tue, 08 Dec 2009 10:15:11 +

Revision: http://svn.php.net/viewvc?view=revision&revision=291869

Log:
add missing includes, fix compile warnings

Changed paths:
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c

Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c
===
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c 2009-12-08 
09:29:30 UTC (rev 291868)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c 2009-12-08 
10:15:11 UTC (rev 291869)
@@ -27,6 +27,14 @@
 #include 
 #include 

+#ifdef FPM_AUTOCONFIG_H
+#include 
+#else
+#include 
+#endif
+#include 
+#include 
+
 #ifdef _WIN32

 #include 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-CVS] svn: /php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/ fastcgi.c

2009-12-07 Thread Antony Dovgal
tony2001 Mon, 07 Dec 2009 10:17:16 +

Revision: http://svn.php.net/viewvc?view=revision&revision=291811

Log:
add missing FPM-specific code

Changed paths:
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c

Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c
===
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c 2009-12-07 
08:47:18 UTC (rev 291810)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c 2009-12-07 
10:17:16 UTC (rev 291811)
@@ -922,6 +922,7 @@
close(req->fd);
 #endif
req->fd = -1;
+   fpm_request_finished();
}
 }

@@ -968,6 +969,8 @@
sa_t sa;
socklen_t len = sizeof(sa);

+   fpm_request_accepting();
+
FCGI_LOCK(req->listen_socket);
req->fd = accept(listen_socket, (struct 
sockaddr *)&sa, &len);
FCGI_UNLOCK(req->listen_socket);
@@ -1007,6 +1010,8 @@
struct pollfd fds;
int ret;

+   fpm_request_reading_headers();
+
fds.fd = req->fd;
fds.events = POLLIN;
fds.revents = 0;
@@ -1019,6 +1024,8 @@
}
fcgi_close(req, 1, 0);
 #else
+   fpm_request_reading_headers();
+
if (req->fd < FD_SETSIZE) {
struct timeval tv = {5,0};
fd_set set;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[PHP-CVS] svn: /php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/ fastcgi.c fastcgi.h fpm_main.c

2009-12-02 Thread Antony Dovgal
tony2001 Wed, 02 Dec 2009 15:05:12 +

Revision: http://svn.php.net/viewvc?view=revision&revision=291594

Log:
add missing patch for fpm(cgi)_main.c

Changed paths:
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.h
U   php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_main.c

Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c
===
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c	2009-12-02 13:56:50 UTC (rev 291593)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.c	2009-12-02 15:05:12 UTC (rev 291594)
@@ -249,6 +249,11 @@
 	}
 }

+void fcgi_set_is_fastcgi(int new_value)
+{
+	is_fastcgi = new_value;
+}
+
 void fcgi_set_in_shutdown(int new_value)
 {
 	in_shutdown = new_value;
@@ -875,7 +880,7 @@
 	return n;
 }

-static inline void fcgi_close(fcgi_request *req, int force, int destroy)
+void fcgi_close(fcgi_request *req, int force, int destroy)
 {
 	if (destroy && req->env) {
 		zend_hash_destroy(req->env);

Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.h
===
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.h	2009-12-02 13:56:50 UTC (rev 291593)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fastcgi.h	2009-12-02 15:05:12 UTC (rev 291594)
@@ -121,8 +121,10 @@
 int fcgi_accept_request(fcgi_request *req);
 int fcgi_finish_request(fcgi_request *req, int force_close);

+void fcgi_set_is_fastcgi(int new_value);
 void fcgi_set_in_shutdown(int);
 void fcgi_set_allowed_clients(char *);
+void fcgi_close(fcgi_request *req, int force, int destroy);

 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);

Modified: php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_main.c
===
--- php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_main.c	2009-12-02 13:56:50 UTC (rev 291593)
+++ php/php-src/branches/PHP_5_3_FPM/sapi/fpm/fpm/fpm_main.c	2009-12-02 15:05:12 UTC (rev 291594)
@@ -63,6 +63,10 @@
 # include 
 #endif

+#if HAVE_FCNTL_H
+# include 
+#endif
+
 #include "zend.h"
 #include "zend_extensions.h"
 #include "php_ini.h"
@@ -91,6 +95,14 @@

 #include "fastcgi.h"

+#ifdef FPM_AUTOCONFIG_H
+#include 
+#else
+#include 
+#endif
+#include 
+#include 
+
 #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;
@@ -100,10 +112,6 @@

 #ifndef PHP_WIN32
 /* these globals used for forking children on unix systems */
-/**
- * Number of child processes that will get created to service requests
- */
-static int children = 0;

 /**
  * Set to non-zero if we are the parent process
@@ -122,6 +130,10 @@
 static pid_t pgroup;
 #endif

+static int request_body_fd;
+
+static char *sapi_cgibin_getenv(char *name, size_t name_len TSRMLS_DC);
+
 #define PHP_MODE_STANDARD	1
 #define PHP_MODE_HIGHLIGHT	2
 #define PHP_MODE_INDENT		3
@@ -134,7 +146,6 @@

 static const opt_struct OPTIONS[] = {
 	{'a', 0, "interactive"},
-	{'b', 1, "bindpath"},
 	{'C', 0, "no-chdir"},
 	{'c', 1, "php-ini"},
 	{'d', 1, "define"},
@@ -151,6 +162,7 @@
 	{'w', 0, "strip"},
 	{'?', 0, "usage"},/* help alias (both '?' and 'usage') */
 	{'v', 0, "version"},
+	{'y', 1, "fpm-config"},
 	{'z', 1, "zend-extension"},
  	{'T', 1, "timing"},
 	{'-', 0, NULL} /* end of args */
@@ -169,6 +181,7 @@
 	zend_bool impersonate;
 #endif
 	HashTable user_config_cache;
+	char *error_header;
 } php_cgi_globals_struct;

 /* {{{ user_config_cache
@@ -495,7 +508,27 @@
 	while (read_bytes < count_bytes) {
 		if (fcgi_is_fastcgi()) {
 			fcgi_request *request = (fcgi_request*) SG(server_context);
-			tmp_read_bytes = fcgi_read(request, buffer + read_bytes, count_bytes - read_bytes);
+			if (request_body_fd == -1) {
+char *request_body_filename = sapi_cgibin_getenv((char *) "REQUEST_BODY_FILE",
+		sizeof("REQUEST_BODY_FILE")-1 TSRMLS_CC);
+
+if (request_body_filename && *request_body_filename) {
+	request_body_fd = open(request_body_filename, O_RDONLY);
+
+	if (0 > request_body_fd) {
+		php_error(E_WARNING, "REQUEST_BODY_FILE: open('%s') failed: %s (%d)",
+request_body_filename, strerror(errno), errno);
+		return 0;
+	}
+}
+			}
+
+			/* If REQUEST_BODY_FILE variable not available - read post body from fastcgi stream */
+			if (request_body_fd < 0) {
+tmp_read_bytes = fcgi_read(request, buffer + read_bytes, count_bytes - read_bytes);
+			} else {
+tmp_read_bytes = read(request_body_fd, buffer + read_bytes, count_bytes - read_bytes);
+			}
 		} else {
 			tmp_read_bytes = read(STDIN_FILENO, buffer + read_bytes, count_bytes - read_bytes);
 		}
@@ -956,6 +989,8 @@
 "  -s   Display colour