You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Shane Caraveo <sh...@caraveo.com> on 1998/02/08 20:23:34 UTC

FW: [PHP-DEV] Re: The Bad News and even more ;)

Hello, this is a message I sent to the php-dev list in response to the info
about the problem with file functions and cgi in apache.  I got knocked off
this list a while back, and only now got around to resubscribing...I've just
listed out some ideas about how to handle a simular issue we are haveing in
php win32.

-----Original Message-----
From: Shane Caraveo [mailto:shane@caraveo.com]
Sent: Sunday, February 08, 1998 12:22 AM
To: Rasmus Lerdorf; php-dev@php.iquest.net
Subject: RE: [PHP-DEV] Re: The Bad News and even more ;)


> Shane, or perhaps we have some other Windows-heads here, the ApacheNT
> project has hit a bit of a roadblock.  If anybody can shed some light on
> it, please let us know.

Hello,
Looks like Steve hit on what might be more the problem, but I haven't looked
at the source.  Anway, we also actualy hit a problem related to this in the
implementation of urls in our file includes.  I'm sure there are other
related problems to M$'s half-assed implementation of c-lib functions.
Anyway, what I was going to do in php is basicly use defines and macros to
change things depending on which platform we compile to.  Something along
the line of the code below (way below), which I'm just writing up now.  The
only thing is that we would have to use a variable for c (see defines below)
that can be passed for win32.  In win32, &s=&c, whereas in unix, well, you
know...  Anyway, these functions (win32 api readfile,writefile) are MUCH
more flexible than msvc c-lib functions.  For instance, like the unix c-lib
functions, you can access sockets through the win32 api functions, whereas
the msvc c-lib functions you cannot.  What I've writen below should be close
to working for a single thread, but if you are opening a file in
process/thread a and passing it to process b, you have to add aditional info
to CreateFile.

Another option that we should take a good and serious look at is the
cross-platform library I pointed out last week.  I know it was knocked down
before, but, this library is in use already in at least one cross-platform
webserver, so its worth some serious consideration.  If I had known about it
when I started work on PHP, no-one would have had the choice ;), I would
have just used it!  It could have saved me a lot of time and pain.  I think
it could still save us some debugging pain, and also have the benefit of
maybe forming a community that uses it for cross-platform development.  Not
all parts of the library need to be used, but there is some usefull stuff in
there (INCLUDING MIME ENCODE AND DECODE!! for those mime functions that were
being discussed).  There are also process controll functions that may help
apache with their problem.  The library is licensed to that it may be freely
used even in commercial software.  It is the only cross-platform library I
have found with such a license.  www.imatix.com

Here is the defines idea I have for file functions...there is a little added
overhead to file opens on windows.  It's not finished, and certainly not
tested to see if it will actualy work.

#if WIN32|WINNT
#define FHANDLE HANDLE
#define FOPEN(fn,m,p) win32_OpenFile(fn,m)
#define FWRITE(b,s,c,f) WriteFile(f,b,s,&c,NULL)
#define FREAD(b,s,c,f) ReadFile(f,b,s,&c,NULL)
#define FCLOSE(f) CloseHandle(f)
#else
#define FHANDLE FILE *
#define FOPEN(fn,m) fopen(fn,m)
#define FWRITE(b,s,c,f) fwrite(b,s,c,f)
#define FREAD(b,s,c,f) fread(b,s,c,f)
#define FCLOSE(f) fclose(f)
#endif

#if WIN32|WINNT
HANDLE win32_OpenFile(char *filename, char *artrib){
	HANDLE file=NULL;
	DWORD access=NULL;
	DWORD sharemode=NULL;
	LPSECURITY_ATTRIBUTES lpSecurityAttributes=NULL;
	DWORD creation=NULL;
	DWORD dwFlagsAndAttributes=NULL;
	HANDLE TemplateFile=NULL;
	append=0;

	switch(attrib){
	case "w":
	access=GENERIC_WRITE;
	creation=TRUCATE_EXISTING;
	break;
	case "r":
	access=GENERIC_READ;
	creation=OPEN_EXISTING;
	break;
	case "a":
	access=GENERIC_WRITE|GENERIC_READ;
	creation=OPEN_ALWAYS;
	append=1;
	break;
	case "w+":
	access=GENERIC_WRITE|GENERIC_READ;
	creation=TRUCATE_EXISTING;
	break;
	case "r+":
	access=GENERIC_WRITE|GENERIC_READ;
	creation=OPEN_EXISTING;
	break;
	case "a+":
	access=GENERIC_WRITE|GENERIC_READ;
	creation=OPEN_ALWAYS;
	append=2;
	break;
	default: /*incorrect attributes*/
		return NULL;
	}

	/*createfile is a misnomer.  It can create or just open a 	file*/
	file=CreateFile(filename,access,sharemode,lpSecurityAttributes,
	creation,dwFlagsAndAttributes,TemplateFile);

	if(append){/*seek to eof and delete eof if append=2*/}
	return FILE;
}
#endif


>
>
> So we have two options in my opinion.
>
> 1) We can try and enlist help from the "community at large" in solving
> this, but distributing to apache-announce and/or on the web site a concise
> description of the bug (like below + more details about the code), so that
> maybe someone outside of the membership of new-httpd can think of
something
> to help us.
>
> 2) We officially declare CGI "unreliable" on Win32.  How vetted has
> mod_isapi been?
>
> 3) We switch to using native win32 handles.  How much effort is this?  Are
> the semantics too different to do a "#define open() Win32open()" kind of
> thing?
>
> 	Brian
>
> At 09:49 PM 2/7/98 +0000, Ben Laurie wrote:
> >OK, its official. _flushall() doesn't make any difference to the Win32
> >CGI hang problem, sad to say. For those having problems reproducing it,
> >the recipe I'm using is this:
> >
> >1. Have a CGI that does a sleep(2).
> >2. Hit the CGI from 10+ DOS windows with a client that just goes round
> >and round refetching.
> >
> >I've found that 8 windows can take half an hour or more, but 11 (or is
> >it 12, too lazy to count) only takes around 10 minutes or less. To hang,
> >that is.
> >
> >BTW, I'm 99% convinced this is an MS bug, not an Apache one, and they
> >aren't paying me enough to fix it. For any Doubting Thomases - the
> >reason other similar programs don't suffer is that they don't use the
> >C/Unix file handling emulation that MS provide - they use native Win32
> >handles. Which, presumably, is what we'll do to in some future version.
> >Perhaps not so future, at this rate. I can't say that the prospect of
> >fixing MS's C library fills me with excitement.
> >
> >Cheers,
> >
> >Ben.
> >
> >--
> >Ben Laurie            |Phone: +44 (181) 735 0686|Apache Group member
> >Freelance Consultant  |Fax:   +44 (181) 735 0689|http://www.apache.org
> >and Technical Director|Email: ben@algroup.co.uk |Apache-SSL author
> >A.L. Digital Ltd,     |http://www.algroup.co.uk/Apache-SSL
> >London, England.      |"Apache: TDG" http://www.ora.com/catalog/apache
> >
> --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
> specialization is for insects				  brian@organic.com
>
>