Apache 2, PHP, caching, and relative file path problems
written by craig, 20 July 2007
For a while, I was under the impression that TACS, our webpage template and caching system, did not work in PHP 4 when running Apache 2 on Windows. It took a while to find the real answer … when PHP 4 or 5 is running as an Apache 2 SAPI module, relative file paths passed to functions such as file_exists() may fail under certain conditions. So far, I’ve discovered that code using ob_start() to cache the page will cause the failure. Running PHP as a CGI binary or code that does not use ob_start() appears to work fine.
The relative file path problem occurs on Windows, but I’m yet to test it on Linux. I’ve found a brief mention of the problem on a PHP-Nuke message board, but there was no resolution. It’s quite obscure so I doubt many developers have come across it.
The only solution I’ve found is to check the absolute, fully-qualified, file location instead. This has now been implemented in TACS v1.1 – if an file cannot be located at the relative location, it will try the absolute path instead. It appears to work fine, but I’d be grateful to hear from anyone who experiences problems.