Windows PHP/Apcahe config question - #! vs. extensions in registry 
July 17th, 2005, 09:56 AM
| | | Windows PHP/Apcahe config question - #! vs. extensions in registry
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 | 
July 17th, 2005, 09:56 AM
| | | 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. | 
July 17th, 2005, 09:57 AM
| | | 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. | 
July 17th, 2005, 09:57 AM
| | | 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> | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,989 network members.
|