summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Mansell <joosters@php.net>2002-03-11 13:37:25 +0000
committerBen Mansell <joosters@php.net>2002-03-11 13:37:25 +0000
commit8ac087a232b678c51db02c55f707fc6d5703505e (patch)
tree5fdc600c8182597d320557f873e385af3166199b
parent2a8d55ff1df39808db90b5ff4be9f3406b690c20 (diff)
downloadphp-git-8ac087a232b678c51db02c55f707fc6d5703505e.tar.gz
Add command line option to FastCGI SAPI to make it bind & listen to a
socket. This makes setting up 'remote' fastcgi much easier.
-rw-r--r--sapi/fastcgi/fastcgi.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/sapi/fastcgi/fastcgi.c b/sapi/fastcgi/fastcgi.c
index d79f8f1130..7170844636 100644
--- a/sapi/fastcgi/fastcgi.c
+++ b/sapi/fastcgi/fastcgi.c
@@ -363,7 +363,9 @@ int main(int argc, char *argv[])
zend_llist global_vars;
int max_requests = 500;
int requests = 0;
+ int fcgi_fd = 0;
int env_size, cgi_env_size;
+ FCGX_Request request;
#ifdef ZTS
zend_compiler_globals *compiler_globals;
zend_executor_globals *executor_globals;
@@ -377,9 +379,29 @@ int main(int argc, char *argv[])
#endif
if( FCGX_IsCGI() ) {
- fprintf( stderr, "The FastCGI version of PHP cannot be "
- "run as a CGI application\n" );
- exit( 1 );
+ /* Did a bind address or port get configured on the command line? */
+ if( argc >= 2 ) {
+ /* 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)
+ */
+ int port = atoi( argv[ 1 ] );
+ if( port ) {
+ char bindport[ 32 ];
+ snprintf( bindport, 32, ":%s", argv[ 1 ] );
+ fcgi_fd = FCGX_OpenSocket( bindport, 128 );
+ } else {
+ fcgi_fd = FCGX_OpenSocket( argv[ 1 ], 128 );
+ }
+ if( fcgi_fd < 0 ) {
+ fprintf( stderr, "Couldn't create FastCGI listen socket\n" );
+ exit( 1 );
+ }
+ } else {
+ fprintf( stderr, "The FastCGI version of PHP cannot be "
+ "run as a CGI application\n" );
+ exit( 1 );
+ }
}
/* Calculate environment size */
@@ -450,6 +472,10 @@ int main(int argc, char *argv[])
}
}
+ /* Initialise FastCGI request structure */
+ FCGX_Init();
+ FCGX_InitRequest( &request, fcgi_fd, 0 );
+
if( children ) {
int running = 0;
int i;
@@ -521,12 +547,16 @@ int main(int argc, char *argv[])
fprintf( stderr, "Going into accept loop\n" );
#endif
- while( FCGX_Accept( &in, &out, &err, &cgi_env ) >= 0 ) {
+ while( FCGX_Accept_r( &request ) >= 0 ) {
#ifdef DEBUG_FASTCGI
fprintf( stderr, "Got accept\n" );
#endif
+ in = request.in;
+ out = request.out;
+ err = request.err;
+ cgi_env = request.envp;
cgi_env_size = 0;
while( cgi_env[ cgi_env_size ] ) { cgi_env_size++; }
merge_env = malloc( (env_size+cgi_env_size)*sizeof(char*) );