Connecting Tech Pros Worldwide Forums | Help | Site Map

Windows PHP/Apcahe config question - #! vs. extensions in registry

jeff@evansdata.com
Guest
 
Posts: n/a
#1: Jul 17 '05
I am developing in PHP on a Windows environment but deploying to a *nix
flavor.

I would like to use the extension recognition in Apache in my local
environment for cgi, and have set the "ScriptInterpreterSource" value
to "registry" in my Apache config. That said, I need the "#!" line in
my scripts so when I upload them to their "live" directory, the server
can find the php executable.

When I try to run a script locally that has the "#!" line first,
however, I am given this output and warning:

#!/usr/bin/php4
"Warning: Cannot modify header information - headers already sent by
(output started at..." etc.

It seems Apache gleefully delivers the first "#!" line as content. Is
there any way, other than stripping this line, to avoid this? Or do I
need to go back to the old Unix style config, "ScriptInterpreterSource
script"?

-Jeff


musicinmyhead
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Windows PHP/Apcahe config question - #! vs. extensions in registry


If you add to the very top of your page the ob_start(); function in
PHP, that will start an output buffer, so header information will not
be sent until the entire page has been processed.

Just make sure to add ob_end_flush(); to the very end of your page, so
it will empty the buffer.

Chung Leong
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Windows PHP/Apcahe config question - #! vs. extensions in registry


<jeff@evansdata.com> wrote in message
news:1102641174.903636.298610@z14g2000cwz.googlegr oups.com...[color=blue]
> I am developing in PHP on a Windows environment but deploying to a *nix
> flavor.
>
> I would like to use the extension recognition in Apache in my local
> environment for cgi, and have set the "ScriptInterpreterSource" value
> to "registry" in my Apache config. That said, I need the "#!" line in
> my scripts so when I upload them to their "live" directory, the server
> can find the php executable.
>
> When I try to run a script locally that has the "#!" line first,
> however, I am given this output and warning:
>
> #!/usr/bin/php4
> "Warning: Cannot modify header information - headers already sent by
> (output started at..." etc.
>
> It seems Apache gleefully delivers the first "#!" line as content. Is
> there any way, other than stripping this line, to avoid this? Or do I
> need to go back to the old Unix style config, "ScriptInterpreterSource
> script"?
>
> -Jeff[/color]

Use an auto_prepend file and an auto_append file. In the former, turn on
output buffering with a call to ob_start(). In the latter, strip off the #!
line from the captured output with preg_replace() and echo it.

Both settings are in php.ini.


jeff@evansdata.com
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Windows PHP/Apcahe config question - #! vs. extensions in registry


Thanks, Chung (and music), this ended up doing the trick:

<snip from prepend>

<?php
function shbstrip($buffer){
return (preg_replace("/^#!.+\n/", "", $buffer, 1));
}
ob_start("shbstrip");
?>

</snip>

<snip from append>

<?php
ob_end_flush();
?>

</snip>

Closed Thread