php.net |  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
Votes:1
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:
MUST BE VALID
Solve the problem:
47 - 42 = ?
Subscribe to this entry?

 
 [2010-09-23 05:00 UTC] stepotronic at web dot de
Description:
------------
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 config.inc.php.

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:
canonicalize,stat,include_once_override,ttl


Current configuration:
;apc configured with pthread mutex locks; best tradedoff performance,compatibility, stability
extension="apc.so"
apc.enabled=1
;one shared memory segment required
apc.shm_segments=1
;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
apc.shm_size=1500
;Hints optimize hash lookup tables
apc.num_files_hint=5000
;Hints optimize hash lookup tables
apc.user_entries_hint=25000
;disabling updates will increase performance; REQUIERES RESTART or apc_cache_clear() to update
;apc.stat=FALSE
;CVS, SNV and rsync backdate modified times; check the creation time for updates
;apc.stat_ctime=FALSE
;spread load on startup by only caching given percent of requests
apc.slam_defense=0
;a non blocking write lock provides a better solution to setting slam_defense
apc.write_lock=1
;read updated files after given delay to prevent loading incomplete files
apc.file_update_protection=5
apc.ttl=300
apc.user_ttl=0
;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
apc.gc_ttl=3600
;limits the maximum file size that will be cached
apc.max_file_size=1M
;a regular expression that excludes files from beeing cached
apc.filters=NULL
;setting to zero causes files to only cache if they match apc.filters
apc.cache_by_default=1
;logs files exluded due to early/late binding issues
apc.report_autofilter=0
;process localized cache
apc.localcache=0
apc.localcache.size=512
#apc.optimization=0
apc.mmap_file_mask="/var/apc/apc.XXXXXX"
apc.enable_cli=1
;optimizes include_once() calls
;apc.include_once_override=0




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

--------------------------------------------
Structure:
--------------------------------------------
/var/www/test/html/de/index.php
/var/www/test/html/de/included.php
/var/www/test/html/de/config/config.inc.php
/var/www/test/html/en/included.php -> ../de/included.php
/var/www/test/html/en/index.php -> ../de/index.php
/var/www/test/html/en/config/config.inc.php
/var/www/test/html/fr/included.php -> ../de/included.php
/var/www/test/html/fr/index.php -> ../de/index.php
/var/www/test/html/fr/config/config.inc.php
--------------------------------------------
Files:
--------------------------------------------
/var/www/test/html/de/index.php:
<?
include('./included.php');
----------------------------------------------------------
/var/www/test/html/de/included.php:
<?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>";
include('./config/config.inc.php');
echo $configvar;
print "<hr>";
include(getcwd() . '/config/config.inc.php');
echo $configvar;
---------------------------------------------------------
/var/www/test/html/de/config.inc.php:
<?php
$configvar = "this is german";
---------------------------------------------------------
/var/www/test/html/en/config.inc.php:
<?php
$configvar = "this is english";
---------------------------------------------------------
/var/www/test/html/fr/config.inc.php:
<?php
$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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-23 05:28 UTC] rasmus@php.net
__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 
include('./file.php');
__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] rasmus@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 06:01:29 2024 UTC