By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,041 Members | 1,734 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,041 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

Jul 17 '05 #2

P: n/a
<je**@evansdata.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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


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.
Jul 17 '05 #3

P: n/a
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>

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.