|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59435 opcache + symlinks + absolute includes fail to resolve to the correct files
Submitted: 2010-09-23 05:00 UTC Modified: 2010-09-27 03:36 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: stepotronic at web dot de Assigned:
Status: Wont fix Package: APC (PECL)
PHP Version: 5.2.9 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
12 - 6 = ?
Subscribe to this entry?

 [2010-09-23 05:00 UTC] stepotronic at web dot de
We have a forum software running in multiple languages. Each language is organized in a subfolder with different language and template caches. Further there is a config file with connection data for a MySQL database. Code files, that contain the same code are simply linked. We use the opcache to boost the performance of the site. Yesterday we came across an incident where, after the reload of the apache, we were left with mixed languages whithin the forums.

I created a little testsetup which allows to reproduce this bug. Let's say we have a vhost named test with the sources in test/html/.

There are basically 2 main code-files and 1 config-file needed. The index.php simply includes the included.php. The included.php again includes a config file located in the subfolder config called

When loading the page for the first time it might already happen, that the wrong configuration is shown. If you switch the language it is clear what the problem is. The only workaround for this seems to be to include getcwd or dirname($_SERVER['SCRIPT_FILENAME']) in front of every include. Trying it with dirname(__FILE__) does not work.

It is now impossible to use relative includes. The workaroud with getcwd() is possible, but it requires a lot of code changes to make it work again.

We tested it with APC 3.1.3pl1 and 3.1.4.
Various parameter changes did not help:

Current configuration:
;apc configured with pthread mutex locks; best tradedoff performance,compatibility, stability
;one shared memory segment required
;size needs to hold all file and user entries; monitor usage using apc.php; extra space is required for deleted entries; behaves poorly when memory is at capacity
;Hints optimize hash lookup tables
;Hints optimize hash lookup tables
;disabling updates will increase performance; REQUIERES RESTART or apc_cache_clear() to update
;CVS, SNV and rsync backdate modified times; check the creation time for updates
;spread load on startup by only caching given percent of requests
;a non blocking write lock provides a better solution to setting slam_defense
;read updated files after given delay to prevent loading incomplete files
;inline garbage collector removes deleted entries from cache as soons as possible; entries still in user by a request will be removed after the gc_ttl has expired
;limits the maximum file size that will be cached
;a regular expression that excludes files from beeing cached
;setting to zero causes files to only cache if they match apc.filters
;logs files exluded due to early/late binding issues
;process localized cache
;optimizes include_once() calls

Reproduce code:
The code is a pretty simple setup of files. I formated the following text a little to help navigating:

/var/www/test/html/en/included.php -> ../de/included.php
/var/www/test/html/en/index.php -> ../de/index.php
/var/www/test/html/fr/included.php -> ../de/included.php
/var/www/test/html/fr/index.php -> ../de/index.php
print "<table>";
print "<tr><td>__FILE__:</td><td>" . dirname(__FILE__) . "</td></tr>";
print "<tr><td>\$_SERVER['SCRIPT_FILENAME']:</td><td>" . dirname($_SERVER['SCRIPT_FILENAME']). "</td></tr>";
print "<tr><td>getcwd():</td><td>" . getcwd(). "</td></tr>";
print "</table>";
echo $configvar;
print "<hr>";
include(getcwd() . '/config/');
echo $configvar;
$configvar = "this is german";
$configvar = "this is english";
$configvar = "this is french";

Expected result:
The software should be running within the folder it was started from. Symlinks are to be used as intended, to use the files as if they were actually placed in that directory.

Actual result:
The script mentioned above shows this result after calling the german page(server restarted):
__FILE__:	/var/www/test/html/de
$_SERVER['SCRIPT_FILENAME']:	/var/www/test/html/de
getcwd():	/var/www/test/html/de
this is german
this is german

and then this result after calling the french:
__FILE__:	/var/www/test/html/de
$_SERVER['SCRIPT_FILENAME']:	/var/www/test/html/fr
getcwd():	/var/www/test/html/fr
this is german
this is french

and this after calling the english:
__FILE__:	/var/www/test/html/de
$_SERVER['SCRIPT_FILENAME']:	/var/www/test/html/en
getcwd():	/var/www/test/html/en
this is german
this is english


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-23 05:28 UTC]
__FILE__ is a compile-time constant.  Same with __DIR__, 
__LINE__, __CLASS__ and other similar constants.  APC caches 
the result of the compile,  It is really that simple, and I 
don't consider this an APC bug at all.  You have to keep this 
in mind when you are building things.
 [2010-09-23 07:53 UTC] stepotronic at web dot de
Sorry, but please read the full bug report.
It is still wrong for apc to change the behaviour of 
__FILE__ was just used here to demonstrate where script currently points to.

The files included are wrong. Please check the example.
 [2010-09-27 03:36 UTC]
Nope, it is still bogus.  Or at least a Won't Fix.  Relative 
include paths are expanded at compile time.  Symlinking a 
script with relative paths to multiple locations is going to 
break things and there is no easy fix that doesn't severely 
hurt performance.  This is a "Don't do that" for opcode-
caching.  Either apc.filter out those files, or don't use 
relative paths (as you discovered on your own.)
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Jul 04 03:03:50 2022 UTC