|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-07-02 21:53 UTC] rpeters at icomproductions dot ca
Description: ------------ Since __FILE__ is defined at compile-time, it means that files that "change location" (eg: are renamed, or hard-linked with multiple filenames) execute incorectly when pre-compiled. This is especially evident with op-code caches such as APC. So __FILE__ either needs to be determined at runtime, or a runtime accessible alternative needs to be provided. I propose $_SERVER['PHP_FILE'], and would like documentation updated to recommend people use it rather than __FILE__. Obviously, __DIR__ would need the $_SERVER['PHP_DIR'] variable for the same reasons. Reproduce code: --------------- CURRENTLY: /1/test.php: <?php require(__DIR__ . '/testDest.php'); ?> /2/test.php created by "cp -l ../1/test.php" /1/testDest.php: <?php echo 1; ?> /2/testDest.php: <?php echo 2; ?> PROPOSED: /1/test.php: <?php require($_SERVER['PHP_DIR'] . '/testDest.php'); ?> /2/test.php created by "cp -l ../1/test.php" /1/testDest.php: <?php echo 1; ?> /2/testDest.php: <?php echo 2; ?> Expected result: ---------------- /1/test.php displays "1", and /2/test.php displays "2" Actual result: -------------- CURRENTLY: When running APC, both scripts will return the results of whichever one you hit first. PROPOSED: When running APC, /1/test.php displays "1", and /2/test.php displays "2" Patchesapc_auto_hardlinks_for_php_5.3.5.diff (last revision 2011-04-27 08:27 UTC by simpcl2008 at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 01:00:01 2025 UTC |
The patch of apc_auto_hardlinks_for_php_5.3.5.diff is to add a new key word "executed_filename" for PHP 5.3.5 . When the following code is running: <?php echo executed_filename; ?> In PHP Runtime, zend_get_executed_filename() is called to returned the current runtime filename and being displayed. To fixed the apc hardlinks programs, the apc source code "apc_main.c" should also to be modified as follows: --- APC-3.1.6/apc_main.c 2010-11-30 18:18:31.000000000 +0800 +++ APC-3.1.6-sae/apc_main.c 2011-04-27 15:56:34.000000000 +0800 @@ -559,6 +559,7 @@ static zend_op_array* my_compile_file(ze if (h->type != ZEND_HANDLE_FILENAME) { zend_llist_add_element(&CG(open_files), h); } + op_array->filename = estrdup(filename); return op_array; } if(APCG(report_autofilter)) {