Ticket #117 (new defect)
__FILE__ doesn't work correctly in hard-linked files
| Reported by: | sherwind@… | Owned by: | moo |
|---|---|---|---|
| Priority: | major | Milestone: | 1.3.0 |
| Component: | cacher | Version: | 1.2.1 |
| Keywords: | dirname hardlink hard link good_report | Cc: | judas.iscariote@… |
| Blocked By: | PHP Version: | 4.3.9 | |
| Application: | Need User Feedback: | no | |
| Other Exts: | SAPI: | Irrelevant | |
| Probability: | Always | Blocking: |
Description (last modified by moo) (diff)
A file that require()s a config file located in dirname(__FILE__) and outputs a constant is hard-linked in multiple sites hosted on the same server. The constant for the site from which the file was first requested gets cached and is returned in subsequent requests, even for other sites.
It works fine if the file is *unhardlinked*. It also works if dirname(__FILE__) is removed or just replaced with './'.
System:
- Centos 4.5
- Apache 2.0.52
- PHP v4.3.9
- XCache v1.2.1
Reproduce code:
foo.example.com and bar.example.com have the same copies of test.php and config.php
# sha1sum /www/*/{test,config}.php
a0af22d58a7a7a5fd11547cd304cc08968c13d5c /www/bar.example.com/test.php
a0af22d58a7a7a5fd11547cd304cc08968c13d5c /www/foo.example.com/test.php
4494ec973dfed496e4b28f1ae6e4e2224d10a66c /www/bar.example.com/config.php
4494ec973dfed496e4b28f1ae6e4e2224d10a66c /www/foo.example.com/config.php
but test.php is hard-linked
# ls -il /www/*/{test,config}.php | awk '{print $1, $10}' | sort -rn
5640819 /www/foo.example.com/test.php
5640819 /www/bar.example.com/test.php
4792040 /www/bar.example.com/config.php
4792039 /www/foo.example.com/config.php
# cat /www/foo.example.com/test.php
<?php
require(dirname(__FILE__) . '/config.php');
echo ABSPATH;
?>
# cat /www/foo.example.com/config.php
<?php
define('ABSPATH', dirname(__FILE__).'/');
?>
Expected result:
"echo ABSPATH;" should return the ABSPATH for foo if foo.example.com is requested and the ABSPATH for bar if bar.example.com is requested.
Actual result:
# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] # curl -H 'Host: foo.example.com' http://127.0.0.1/test.php /www/foo.example.com/ # curl -H 'Host: bar.example.com' http://127.0.0.1/test.php /www/foo.example.com/ # service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] # curl -H 'Host: bar.example.com' http://127.0.0.1/test.php /www/bar.example.com/ # curl -H 'Host: foo.example.com' http://127.0.0.1/test.php /www/bar.example.com/

