cvs: php4 /sapi/fastcgi fastcgi.c

From: Date: Mon, 11 Mar 2002 13:37:25 +0000
Subject: cvs: php4 /sapi/fastcgi fastcgi.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-9900@lists.php.net to get a copy of this message
joosters Mon Mar 11 08:37:25 2002 EDT Modified files: /php4/sapi/fastcgi fastcgi.c Log: Add command line option to FastCGI SAPI to make it bind & listen to a socket. This makes setting up 'remote' fastcgi much easier. Index: php4/sapi/fastcgi/fastcgi.c diff -u php4/sapi/fastcgi/fastcgi.c:1.23 php4/sapi/fastcgi/fastcgi.c:1.24 --- php4/sapi/fastcgi/fastcgi.c:1.23 Sat Feb 2 14:53:42 2002 +++ php4/sapi/fastcgi/fastcgi.c Mon Mar 11 08:37:25 2002 @@ -363,7 +363,9 @@ 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 @@ #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 @@ } } + /* Initialise FastCGI request structure */ + FCGX_Init(); + FCGX_InitRequest( &request, fcgi_fd, 0 ); + if( children ) { int running = 0; int i; @@ -521,12 +547,16 @@ 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*) );

« previous php.cvs (#9900) next »