Browse Source

Windows compilation of fast cgi now working. See windows.txt for info.

experimental/rand_redesign
Shane Caraveo 25 years ago
parent
commit
108633e1ab
  1. 66
      sapi/fastcgi/fastcgi.c
  2. 108
      sapi/fastcgi/fastcgi.dsp
  3. 35
      sapi/fastcgi/windows.txt

66
sapi/fastcgi/fastcgi.c

@ -49,7 +49,9 @@
#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
@ -59,10 +61,16 @@
#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;
@ -119,7 +127,7 @@ static void sapi_fastcgi_send_header(sapi_header_struct *sapi_header, void *serv
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;
@ -141,21 +149,13 @@ static char *sapi_fastcgi_read_cookies(TSRMLS_D)
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);
}
@ -194,12 +194,31 @@ static sapi_module_struct fastcgi_sapi_module = {
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);
@ -215,16 +234,23 @@ static void init_request_info( TSRMLS_D )
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 '/'
@ -291,16 +317,17 @@ void fastcgi_php_shutdown(void)
*/
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 );
@ -310,15 +337,17 @@ void fastcgi_cleanup(int signal)
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
@ -355,7 +384,7 @@ int main(int argc, char *argv[])
20000419 */
#endif
#endif
sapi_startup(&fastcgi_sapi_module);
if (php_module_startup(&fastcgi_sapi_module)==FAILURE) {
@ -372,6 +401,7 @@ int main(int argc, char *argv[])
}
}
#ifndef PHP_WIN32
/* Pre-fork, if required */
if( getenv( "PHP_FCGI_CHILDREN" )) {
children = atoi( getenv( "PHP_FCGI_CHILDREN" ));
@ -446,6 +476,8 @@ int main(int argc, char *argv[])
}
}
#endif /* WIN32 */
/* Main FastCGI loop */
#ifdef DEBUG_FASTCGI
fprintf( stderr, "Going into accept loop\n" );

108
sapi/fastcgi/fastcgi.dsp

@ -0,0 +1,108 @@
# Microsoft Developer Studio Project File - Name="fastcgi" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=fastcgi - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "fastcgi.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "fastcgi.mak" CFG="fastcgi - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "fastcgi - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "fastcgi - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "fastcgi - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "..\..\Release"
# PROP Intermediate_Dir "..\..\Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# 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
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# 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
# 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"
!ELSEIF "$(CFG)" == "fastcgi - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "c:\php-fcgi"
# PROP Intermediate_Dir "..\..\Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# 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
# SUBTRACT CPP /YX
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# 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
# 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"
!ENDIF
# Begin Target
# Name "fastcgi - Win32 Release"
# Name "fastcgi - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\fastcgi.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\php_fastcgi.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

35
sapi/fastcgi/windows.txt

@ -0,0 +1,35 @@
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.
Loading…
Cancel
Save