]> granicus.if.org Git - php/commitdiff
Add command line option to FastCGI SAPI to make it bind & listen to a
authorBen Mansell <joosters@php.net>
Mon, 11 Mar 2002 13:37:25 +0000 (13:37 +0000)
committerBen Mansell <joosters@php.net>
Mon, 11 Mar 2002 13:37:25 +0000 (13:37 +0000)
socket. This makes setting up 'remote' fastcgi much easier.

sapi/fastcgi/fastcgi.c

index d79f8f11307dee66a77dd8f8ea61fea54c79dc85..71708446366e18a49e1d93c88a8e26a562c5271c 100644 (file)
@@ -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*) );