In our SAPI cgi we have a check along these lines:
if (getenv("SERVER_SOFTWARE")
|| getenv("SERVER_NAME")
|| getenv("GATEWAY_INTERFACE")
|| getenv("REQUEST_METHOD")) {
cgi = 1;
}
if(!cgi) getopt(...)
As in, we do not parse command line args for the cgi binary if we are
running in a web context. At the same time our regression testing system
tries to use the cgi binary and it sets these variables in order to
properly test GET/POST requests. From the regression testing system we
use -d extensively to override ini settings to make sure our test
environment is sane. Of course these two ideas conflict, so currently our
regression testing is somewhat broken. We haven't noticed because we
don't have many tests that have GET/POST data and we rarely build the cgi
binary.
The point of the question here is if anybody remembers why we decided not
to parse command line args for the cgi version? I could easily see it
being useful to be able to write a cgi script like:
#!/usr/local/bin/php-cgi -d include_path=/path
<?php
...
?>
and have it work both from the command line and from a web context.
As far as I can tell this wouldn't conflict with anything, but somebody at
some point must have had a reason for disallowing this.
-Rasmus
The point of the question here is if anybody remembers why we decided not
to parse command line args for the cgi version?
...
As far as I can tell this wouldn't conflict with anything, but somebody at
some point must have had a reason for disallowing this.
It looks like it's been that way since revision 1.1 of cgi_main.c
(from over four years ago):
http://cvs.php.net/co.php/php-src/sapi/cgi/cgi_main.c?login=2&r=1.1
Some additional archaeology says that this logic goes back to PHP 3
(main.c revision 1.354, from 5 years, 11 months ago):
http://cvs.php.net/diff.php/php3/main.c?login=2&r1=1.354&r2=1.355&ty=h
I was kind of hoping it was something you had committed, but no such
luck. =)
--
Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)
Some additional archaeology says that this logic goes back to PHP 3
(main.c revision 1.354, from 5 years, 11 months ago):http://cvs.php.net/diff.php/php3/main.c?login=2&r1=1.354&r2=1.355&ty=h
I was kind of hoping it was something you had committed, but no such
luck. =)
Well, it wouldn't have surprised me. I hit this all the time. I look at
code and wonder who the moron was who wrote it and just before sending out
a nastygram I doublecheck and find that I was that moron.
In this case the check was added by Jaakko Hyvatti in February 98.
Looking at the state of the code from back then I still don't see the
reason why those switches were disallowed when running in a web context.
We have to watch how we handle the query_string of course, but that
doesn't seem like a difficult problem to address.
-Rasmus
#!/usr/local/bin/php-cgi -d include_path=/path
<?php
...
?>and have it work both from the command line and from a web context.
Just a side note.
This does not work on most systems due to kernel limitation on shebang line.
Most systems accept only one argument, and some even limit the length of
that. The only system that I know of which does support this is FreeBSD.
Edin