php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59735 The filename field of the opcode array should be updated when cache hits
Submitted: 2011-04-27 23:07 UTC Modified: 2016-11-18 21:43 UTC
From: simpcl2008 at gmail dot com Assigned:
Status: Wont fix Package: APC (PECL)
PHP Version: 5.3.5 OS: CentOS5
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:
24 + 28 = ?
Subscribe to this entry?

 
 [2011-04-27 23:07 UTC] simpcl2008 at gmail dot com
Description:
------------
In my_compile_file of apc_main.c, the filename of opcode 
array should be updated when opcode array is found in apc 
caches.

There are two php script files a.php & b.php, and one is the 
hard link of the other. They have the same inode value, the 
same file content, and the different file names.

When APC is working with (apc.stat = 1) mode, the inode is 
as the hash key.  Assume there is nothing in APC cache, and 
the script a.php need to be compiled for the first time. The 
filename field of opcode array generated is "a.php".

When b.php need to be executed, opcode array cache hit 
because of b.php has the same inode with a.php. If the 
filename field of the found opcode array is not updated, 
zend_get_executed_filename will return "a.php" but not 
"b.php" during the execute time of b.php. 

zend_get_executed_filename can only get the compiled php 
script file name, but not the executed php script file name.

Reproduce code:
---------------
apply the following patch file to php 5.3.5:
http://bugs.php.net/patch-display.php?bug_id=45421&patch=apc_auto_hardlinks_for_php_5.3.5.diff&revision=1303892859&download=1

php.ini:
  apc.stat = 1

test php scripts:
  1.php
  <?php>
    echo executed_filename . PHP_EOL;
  <?>


cp -l 1.php 2.php
php 1.php
php 2.php

Expected result:
----------------
1.php
2.php

Actual result:
--------------
1.php
1.php

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-27 23:13 UTC] simpcl2008 at gmail dot com
Attach the patch for APC 3.1.6:

--- 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 = 
filename;//estrdup(filename);
             return op_array;
         }
         if(APCG(report_autofilter)) {
 [2011-04-27 23:50 UTC] paulgao at yeah dot net
script:
<?php
echo __FILE__ . PHP_EOL;
?>

ln -s 1.php 2.php

[root@xxx ~]# php 1.php 
/root/1.php
[root@xxx ~]# php 2.php 
/root/1.php
 [2011-04-28 00:23 UTC] simpcl2008 at gmail dot com
Sorry for some incorrent reproduce code!!!

access a.php/b.php by apache/browser:

http://127.0.0.1/a.php
http://127.0.0.1/b.php

not cli: 

php a.php
php b.php
 [2011-04-28 02:36 UTC] gopalv@php.net
This doesn't fix the __FILE__ issue from what I can tell.

It only works for the first file hit in the requests?
 [2011-04-28 02:53 UTC] simpcl2008 at gmail dot com
If you use the keyword 'executed_filename' instead of 
'__FILE__', in all the scripts files you can get the current 
executed file name by 'executed_filename'. Not the first php 
script file in a request.

If you want use the keyword '__FILE__', you must convince 
Zend Dev Team to replace the implement way of '__FILE__' 
with 'executed_filename' .

Do I make myself clear?
 [2011-04-28 03:13 UTC] simpcl2008 at gmail dot com
Hi gopalv,

If you want to replace the __FILE__'s implement, mail to me. 
I'm glad to send you the patch.
 [2016-11-18 21:43 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 [2016-11-18 21:43 UTC] kalle@php.net
APC is no longer supported in favor of opcache that comes bundled with PHP, if you wish to use the user cache, then look at PECL/APCu.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC