php include_once is failing for me with the “failed to open stream: No such file or directory” message, despite the existence of the file it is complaining about, and chmod’ing to 777 in order to try to mitigate the problem.
warning: include_once() [function.include]: Failed opening ‘../i_utility/WCHelper.php’ for inclusion (include_path=’.:/usr/share/pear:/var/www/html/we_/’) in /var/www/i_/php/w_corner/modules/i_ers/i_ers.module on line 6.
From the command line I can cd to the directory containing the source code file (/var/www/i_/php/w_corner/modules/i_ers), and I can ls the file about which php complains “no such”: ../i_utility/WCHelper.php
Indeed, I can do the above after su’ing to the apache user, and can even touch the file and see its last modified timestamp changed:
-bash-3.2$ whoami
apache
-bash-3.2$ cd /var/www/i_/php/w_corner/modules/i_ers
-bash-3.2$ ls -l ../i_utility/WCHelper.php
-rwxrwxrwx 1 root root 32112 Sep 14 09:49 ../i_utility/WCHelper.php
-bash-3.2$ touch ../i_utility/WCHelper.php
-bash-3.2$ ls -l ../i_utility/WCHelper.php
-rwxrwxrwx 1 root root 32112 Sep 27 17:08 ../i_utility/WCHelper.php
In light of all of the above, what could be causing PHP’s include_once to fail under these circumstances?
PHP’s include paths are a bit counter-intuitive, especially when you feed it relative paths. You’d expect the path to be relative to the current file (just like with CSS for example), but PHP interprets them as relative to the current working directory, which is usually the directory where the entry point PHP file resides (e.g.
/var/www/my_site/index.php).The easiest fix is to make use of
dirname(__FILE__), which always maps to the absolute location of the current script file.