#if HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifndef PHP_WIN32
#include <sys/wait.h>
+#endif
#include <sys/stat.h>
#if HAVE_SYS_TYPES_H
#include <signal.h>
#endif
+#ifndef S_ISREG
+#define S_ISREG(mode) ((mode) & _S_IFREG)
+#endif
+
FCGX_Stream *in, *out, *err;
FCGX_ParamArray envp;
char *path_info = NULL;
+#ifndef PHP_WIN32
struct sigaction act, old_term, old_quit, old_int;
+#endif
/* Our original environment from when the FastCGI first started */
char **orig_env;
static int sapi_fastcgi_read_post(char *buffer, uint count_bytes TSRMLS_DC)
{
- size_t read_bytes = 0, tmp;
+ size_t read_bytes = 0;
int c;
char *pos = buffer;
static void sapi_fastcgi_register_variables(zval *track_vars_array TSRMLS_DC)
{
- char *self = getenv("REQUEST_URI");
- char *ptr = strchr( self, '?' );
-
- /*
- * note that the environment will already have been set up
- * via fastcgi_module_main(), below.
- *
- * fastcgi_module_main() -> php_request_startup() ->
- * php_hash_environment() -> php_import_environment_variables()
+ /* In CGI mode, we consider the environment to be a part of the server
+ * variables
*/
+ php_import_environment_variables(track_vars_array TSRMLS_CC);
- /* strip query string off this */
- if ( ptr ) *ptr = 0;
- php_register_variable( "PHP_SELF", getenv("REQUEST_URI"), track_vars_array TSRMLS_CC);
- if ( ptr ) *ptr = '?';
+ /* Build the special-case PHP_SELF variable for the CGI version */
+ php_register_variable("PHP_SELF", (SG(request_info).request_uri ? SG(request_info).request_uri:""), track_vars_array TSRMLS_CC);
}
static void fastcgi_module_main(TSRMLS_D)
{
zend_file_handle file_handle;
+ int c, retval = FAILURE;
file_handle.type = ZEND_HANDLE_FILENAME;
file_handle.filename = SG(request_info).path_translated;
file_handle.free_filename = 0;
file_handle.opened_path = NULL;
+ /* eat the bang line */
+ if (SG(request_info).path_translated) {
+ retval = php_fopen_primary_script(&file_handle TSRMLS_CC);
+ }
+
+ if (retval == SUCCESS) {
+ /* #!php support */
+ c = fgetc(file_handle.handle.fp);
+ if (c == '#') {
+ while (c != 10 && c != 13) {
+ c = fgetc(file_handle.handle.fp); /* skip to end of line */
+ }
+ CG(zend_lineno)++;
+ } else {
+ rewind(file_handle.handle.fp);
+ }
+ }
+
if (php_request_startup(TSRMLS_C) == SUCCESS) {
php_execute_script(&file_handle TSRMLS_CC);
php_request_shutdown(NULL);
struct stat st;
char *pi = getenv( "PATH_INFO" );
char *pt = getenv( "PATH_TRANSLATED" );
+ if (!pt) {
+ pt = getenv("SCRIPT_FILENAME"); // apache mod_fastcgi sets this
+ }
path_info = strdup( pi );
SG(request_info).request_method = getenv("REQUEST_METHOD");
SG(request_info).query_string = getenv("QUERY_STRING");
SG(request_info).request_uri = path_info;
+ if (!SG(request_info).request_uri) {
+ SG(request_info).request_uri = getenv("SCRIPT_NAME");
+ }
SG(request_info).content_type = ( content_type ? content_type : "" );
SG(request_info).content_length = (content_length?atoi(content_length):0);
SG(sapi_headers).http_response_code = 200;
SG(request_info).path_translated = pt;
+ if (!pt) return;
/*
* if the file doesn't exist, try to extract PATH_INFO out
* of it by stat'ing back through the '/'
*/
void fastcgi_cleanup(int signal)
{
- int i;
#ifdef DEBUG_FASTCGI
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 );
int main(int argc, char *argv[])
{
int exit_status = SUCCESS;
+#ifndef PHP_WIN32
int c, i, len;
zend_file_handle file_handle;
char *s;
+ int status;
+#endif
char *argv0=NULL;
char *script_file=NULL;
zend_llist global_vars;
int max_requests = 500;
int requests = 0;
- int status;
int env_size, cgi_env_size;
#ifdef DEBUG_FASTCGI
20000419 */
#endif
#endif
-
+
sapi_startup(&fastcgi_sapi_module);
if (php_module_startup(&fastcgi_sapi_module)==FAILURE) {
}
}
+#ifndef PHP_WIN32
/* Pre-fork, if required */
if( getenv( "PHP_FCGI_CHILDREN" )) {
children = atoi( getenv( "PHP_FCGI_CHILDREN" ));
}
}
+#endif /* WIN32 */
+
/* Main FastCGI loop */
#ifdef DEBUG_FASTCGI
fprintf( stderr, "Going into accept loop\n" );
--- /dev/null
+# Microsoft Developer Studio Project File - Name="fastcgi" - Package Owner=<4>\r
+# Microsoft Developer Studio Generated Build File, Format Version 6.00\r
+# ** DO NOT EDIT **\r
+\r
+# TARGTYPE "Win32 (x86) Console Application" 0x0103\r
+\r
+CFG=fastcgi - Win32 Debug\r
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r
+!MESSAGE use the Export Makefile command and run\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "fastcgi.mak".\r
+!MESSAGE \r
+!MESSAGE You can specify a configuration when running NMAKE\r
+!MESSAGE by defining the macro CFG on the command line. For example:\r
+!MESSAGE \r
+!MESSAGE NMAKE /f "fastcgi.mak" CFG="fastcgi - Win32 Debug"\r
+!MESSAGE \r
+!MESSAGE Possible choices for configuration are:\r
+!MESSAGE \r
+!MESSAGE "fastcgi - Win32 Release" (based on "Win32 (x86) Console Application")\r
+!MESSAGE "fastcgi - Win32 Debug" (based on "Win32 (x86) Console Application")\r
+!MESSAGE \r
+\r
+# Begin Project\r
+# PROP AllowPerConfigDependencies 0\r
+# PROP Scc_ProjName ""\r
+# PROP Scc_LocalPath ""\r
+CPP=cl.exe\r
+RSC=rc.exe\r
+\r
+!IF "$(CFG)" == "fastcgi - Win32 Release"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 0\r
+# PROP BASE Output_Dir "Release"\r
+# PROP BASE Intermediate_Dir "Release"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 0\r
+# PROP Output_Dir "..\..\Release"\r
+# PROP Intermediate_Dir "..\..\Release"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c\r
+# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "NDEBUG" /D "_CONSOLE" /D ZEND_DEBUG=0 /D "MSVC5" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /D "PHP_WIN32" /Fr /FD /c\r
+# SUBTRACT CPP /YX\r
+# ADD BASE RSC /l 0x409 /d "NDEBUG"\r
+# ADD RSC /l 0x409 /d "NDEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\r
+# ADD LINK32 php4nts.lib libfcgi.lib winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /version:4.0 /subsystem:console /machine:I386 /nodefaultlib:"libc.lib" /out:"..\..\Release/php-fcgi.exe" /libpath:"..\..\Release" /libpath:"fcgi\lib"\r
+\r
+!ELSEIF "$(CFG)" == "fastcgi - Win32 Debug"\r
+\r
+# PROP BASE Use_MFC 0\r
+# PROP BASE Use_Debug_Libraries 1\r
+# PROP BASE Output_Dir "Debug"\r
+# PROP BASE Intermediate_Dir "Debug"\r
+# PROP BASE Target_Dir ""\r
+# PROP Use_MFC 0\r
+# PROP Use_Debug_Libraries 1\r
+# PROP Output_Dir "c:\php-fcgi"\r
+# PROP Intermediate_Dir "..\..\Debug"\r
+# PROP Ignore_Export_Lib 0\r
+# PROP Target_Dir ""\r
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c\r
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\regex\\" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /I "fcgi\include" /D "DEBUG" /D "_DEBUG" /D "_CONSOLE" /D "MSVC5" /D "PHP_WIN32" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /FR /FD /GZ /c\r
+# SUBTRACT CPP /YX\r
+# ADD BASE RSC /l 0x409 /d "_DEBUG"\r
+# ADD RSC /l 0x409 /d "_DEBUG"\r
+BSC32=bscmake.exe\r
+# ADD BASE BSC32 /nologo\r
+# ADD BSC32 /nologo\r
+LINK32=link.exe\r
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept\r
+# ADD LINK32 winmm.lib wsock32.lib netapi32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4nts_debug.lib libfcgi.lib /nologo /version:4.0 /subsystem:console /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"c:\php-fcgi\php-fcgi.exe" /pdbtype:sept /libpath:"..\..\Debug" /libpath:"fcgi\lib"\r
+\r
+!ENDIF \r
+\r
+# Begin Target\r
+\r
+# Name "fastcgi - Win32 Release"\r
+# Name "fastcgi - Win32 Debug"\r
+# Begin Group "Source Files"\r
+\r
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"\r
+# Begin Source File\r
+\r
+SOURCE=.\fastcgi.c\r
+# End Source File\r
+# End Group\r
+# Begin Group "Header Files"\r
+\r
+# PROP Default_Filter "h;hpp;hxx;hm;inl"\r
+# Begin Source File\r
+\r
+SOURCE=.\php_fastcgi.h\r
+# End Source File\r
+# End Group\r
+# Begin Group "Resource Files"\r
+\r
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"\r
+# End Group\r
+# End Target\r
+# End Project\r
--- /dev/null
+Windows support is currently experimental.
+
+Tested under IIS with cgi-fcgi.exe and Apache with mod_fastcgi.
+
+Compilation:
+Currently only supports Non-Thread safe compilation, however,
+that is realy all that is needed :)
+
+Get the devkit from www.fastcgi.com, build it.
+Create the directories
+ php4/sapi/fastcgi/fcgi
+ php4/sapi/fastcgi/fcgi/include
+ php4/sapi/fastcgi/fcgi/lib
+Place headers and libs in the include and lib directories.
+Load the php.dsw, and compile.
+
+IIS configuration:
+
+Under the application configuration in the IIS configuration program, use:
+.php C:\php-fcgi\cgi-fcgi.exe -connect php c:\php-fcgi\php-fcgi.exe
+
+Apache Configuration:
+
+LoadModule fastcgi_module modules/mod_fastcgi.dll
+<IfModule mod_fastcgi.c>
+AddHandler fastcgi-script fphp php
+</IfModule>
+
+The scripts require the bang line as the first line
+of the script to work with mod_fastcgi,
+#!c:/php-fcgi/php-fcgi.exe
+
+TODO:
+make 'thread-safe' compilation, though it isn't necessary.
+