Opened 12 months ago

Last modified 12 months ago

#371 new defect

Identical files with a static variable that has __DIR__ leads to wrong results.

Reported by: jfk01 Owned by: moo
Priority: critical Milestone: 4.0.0
Component: cacher Version: 3.2.0
Keywords: static variable Cc:
Application: PHP Version: any
Other Exts: SAPI: FastCGI
Probability: Always Blocked By:


My setup is this virtual hosting server:

  • Debian 7.11, Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.88-1 x86_64 GNU/Linux
  • Apache 2.2.22-13+deb7u8
  • PHP 5.6.28 running in FPM mode with UID/GID, open_basedir and chroot separation for virtual domains.
  • Xcache 4.0.0 compiled on Debian 7.11, Linux web 2.6.32-48-pve #1 SMP Fri Dec 23 10:22:54 CET 2016 x86_64 GNU/Linux, gcc version 4.7.2 (Debian 4.7.2-5).

The best thing about Xcache is that identical php files are cached in memory only once even though they reside in different virtual domains. It's saving memory when many clients have similar WordPress? or Joomla installations.

A client called that his domain stopped working, claiming he didn't change anything. Looking briefly at the error showed that the script wants to include non existing file (perhaps misspelled path). I told the client that it's his problem and probably forget to change something in the configuration. But when the same scenario repeated on a different server, I started to investigate the situation. The problem was always in composer's autoload_real.php on line 66 trying to include file from different virtual domain thus breaking the open_basedir restriction. I didn't change anything on the setup neither but the time it stopped working I just restarted the PHP process. It led to a situation when domain A was working and domain B showing an error (trying to include utf8.php from domain's A path) and just after another PHP restart domain B started to work and domain A showed and error (trying to include utf8.php from domain's B path). Long story short, the file autoload_real.php was identical in both domains A and B and the one that loaded first into Xcache kept it's DIR. It only happens when the variable is static and the source files are identical. PHP version is not important, tested on PHP 5.4, 5.5 and 5.6 with same results which led me to the conclusion it must be Xcache issue. Also switching from Xcache to APC or Opcache resolved the issue.

So the minimal test configuration to reproduce the error is 4 php files:


require_once 'testinclude1.php';


static $myfilename=__FILE__;


require_once 'testinclude2.php';


static $myfilename=__FILE__;

After browsing to testmain1.php and then to testmain2.php
i got
string(41) "/var/www/tst56/testcache/testinclude1.php"
string(41) "/var/www/tst56/testcache/testinclude1.php"

while the expected results are
string(41) "/var/www/tst56/testcache/testinclude1.php"
string(41) "/var/www/tst56/testcache/testinclude2.php"

Setting xcache.cacher = Off also resolves the issue.

The content of xcache.ini is:
extension =
xcache.admin.enable_auth = On
xcache.admin.user = "admin"
xcache.admin.pass = "..."
xcache.shm_scheme = "mmap"
xcache.size = 92M
xcache.count = 1
xcache.slots = 8K
xcache.ttl = 7200
xcache.gc_interval = 300
xcache.var_size = 0M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = On
xcache.coverager = Off
xcache.coveragedump_directory = ""

Well, the feature I liked most about Xcache is now probably the reason I must stop using it...

Change History (1)

comment:1 Changed 12 months ago by jfk01

  • Version set to 3.2.0

Xcache 3.2.0 is also affected

Last edited 12 months ago by jfk01 (previous) (diff)
Note: See TracTickets for help on using tickets.