|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 04:00:01 2025 UTC |
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.