Page 1 of 1

"the" in heredoc makes script "not found"

Posted: Fri Jan 12, 2007 10:55 pm
by Riom
I'm in the process of moving some code over to a new server and came across this very obscure bug/feature.

I'm wondering if anybody can reproduce it, it's so odd.

Essentially: a php script cannot be found by Apache if it contains the word "the" in a heredoc (when using a script name without an extension, and a defaulttype of php).

First of all, this is with Apache 2.2.2 and PHP 5.2.0 on Linux (Fedora) ONLY. This DOES NOT happen with earlier versions (my scripts run fine on older servers).

I've set the default type to php in httpd.conf for this virtual server:

Code: Select all

DefaultType application/x-httpd-php
There are no rewrites set for this server.

I create a file called "test" (no extension) that contains:

Code: Select all

<?php
echo <<<EOT
the
EOT;
?>
Now, if I access the file "/test/" through the server Apache tells me "not found".

If I omit the trailing slash, I'm shown the source of the file (i.e. Apache can find it now, but doesn't execute it).

If I change the word in the heredoc to anything other than "the", the php is executed correctly! Even putting text each side of the "the" makes no difference, still fails (I initially found the problem in a full page of text).

Just changing "the" to "them" fixes it. Also, if the script has a .php extension it is always found and executed, this only happens with the defaulttype. I've also typed the code in manually on the server to make sure it's not a line-endings problem.

On another script, again the word "the" is the problem, but for that one it's in a standard echoed string, not a heredoc, which is even stranger.

Any ideas what could have changed to break this type of usage in these latest versions? Is it reproducable?

I'm stuck on what to do about it, other than replace the "e" in "the" with it's html character code!

Re: "the" in heredoc makes script "not found&

Posted: Sat Jan 13, 2007 2:05 am
by volka
Riom wrote:I'm wondering if anybody can reproduce it, it's so odd.
Well, I can't. And it sounds weird to say the least ;)

Posted: Sat Jan 13, 2007 4:40 am
by Ollie Saunders
Yes, this is seriously strange. It is possible that by making files of every type run as PHP you could be creating collisions of purpose. For instance with .htaccess files which by one rule should be executed as PHP and by another should allow for sever configuration. Or am I just barking up the wrong tree.

What happens if you assign the heredoc to a variable and then output the variable?

Posted: Sat Jan 13, 2007 4:15 pm
by Riom
ole wrote:Yes, this is seriously strange. It is possible that by making files of every type run as PHP you could be creating collisions of purpose. For instance with .htaccess files which by one rule should be executed as PHP and by another should allow for sever configuration. Or am I just barking up the wrong tree.

What happens if you assign the heredoc to a variable and then output the variable?
Thanks for the suggestions. I don't have a .htaccess for this site (just the default in the httpd). I run multiple live sites like this without problems, on earlier versions of apache/php. (it's an easy way to get pretty urls like /products/widget/, where the script is "products", without rewrites). So it has worked, up to now...

I've now tried assigning it to a variable - same results as echoing direct.

I'll go through the php.ini and httpd.conf in more detail to check them against my other working installations, it does look like some sort of defaulting problem (it's just the word it picks to break on is so unlikely: "the", only as a word, not as an embedded string).

Posted: Sat Jan 13, 2007 9:29 pm
by Ambush Commander
Have you checked Apache's error logs? Many times I've run into mysterious errors only to be enlightened by some cryptic error message that suddenly goes ding!

Posted: Sat Jan 13, 2007 10:23 pm
by Riom
Ambush Commander wrote:Have you checked Apache's error logs? Many times I've run into mysterious errors only to be enlightened by some cryptic error message that suddenly goes ding!
Yes, it's a standard 404 in the access log and error log when getting /test/, and a 200 or 304 in access log (nothing in error log) when getting /test (no trailing slash) when it just displays source rather than executing the php.

Changing the "the" to something else (like "them" or even "th & # 101 ;" (spaces are just to display it here)), it works fine with or without trailing slash, 200 in access log, nothing in error log. Weird.

Re: "the" in heredoc makes script "not found&

Posted: Sun Jan 14, 2007 9:12 pm
by Riom
volka wrote:
Riom wrote:I'm wondering if anybody can reproduce it, it's so odd.
Well, I can't. And it sounds weird to say the least ;)
Volka, are you using Apache 2.2.2 and PHP 5.2.0?

I've had no problem at all with earlier versions - the scripts with this problem are running fine on busy live sites with Apache 2.0.59 and php 5.1.2, also Apache 2.0.55 and php 5.1.6. It's either the latest versions, or the setup of the server that they are on, that is breaking it.

Posted: Sun Jan 14, 2007 10:00 pm
by Riom
...
SOLVED!

It seems that when this new server was setup, lots of extra modules were enabled on Apache. Including mod_mime_magic.

Disabling that fixes it, by commenting out in httpd.conf:

Code: Select all

LoadModule mime_magic_module modules/mod_mime_magic.so
I confirmed this by enabling it again - breaks the heredocs that contain "the". Turning it off again fixes the problem.

Presumably some string of characters sent from php that includes "the" can interact with the mod_mime_magic. The job of mod_mime_magic is to do things based on specific character sequences, so it's possible to see how it can get involved.

Not really PHP's fault, seems to be an Apache bug/feature, probably depends on the module load order. I couldn't reproduce the bug on an earlier Apache.

Thanks for all the suggestions though. I'll be back when I have a real php problem!

Posted: Sun Jan 14, 2007 11:47 pm
by feyd
That just seems bizarre.

Glad you got it worked out though. :)