|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-10-07 04:40 UTC] p at wspnr dot com
Description:
------------
Calling \opcache_reset() breaks the "require" statement on future page loads. The only thing that seems to fix it is restarting PHP-FPM.
The require fails, stating that it can't find the file path. The file path listed begins with the correct path, but is then followed by junk data. The 'junk' data seems to be other strings from the file(s).
Tested and reproduced on both 64-bit and 32-bit builds.
Test script:
---------------
This is split into three files, running with opcache enabled:
-- file1.php --
<?php
namespace my\nsname;
require 'file3.php';
class MyClass implements MyInterface {}
new MyClass();
echo 'I am file 1';
-- file2.php --
<?php
namespace my\nsname;
\opcache_reset();
echo 'I am file 2';
-- file3.php --
<?php
namespace my\nsname;
interface MyInterface {}
echo 'I am file 3';
-- TEST --
Load, in sequence:
file1.php
file2.php
file3.php
file1.php
Expected result:
----------------
I am file 3
I am file 1
I am file 2
I am file 3
I am file 3
I am file 1
Actual result:
--------------
I am file 3
I am file 1
I am file 2
I am file 3
Fatal error: require(): Failed opening required 'file3.php\myinte' (include_path='.:') in /.../file1.php on line 5
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
actually, it's intentional only copy Z_STRLEN, please verify this fix: diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index eaadac6..18862b3 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -249,24 +249,27 @@ static void accel_interned_strings_restore_state(void) uint nIndex; Bucket *p; - ZCSG(interned_strings_top) = ZCSG(interned_strings_saved_top); - while (idx > 0) { - idx--; - p = ZCSG(interned_strings).arData + idx; - if ((char*)p->key < ZCSG(interned_strings_top)) break; - ZCSG(interned_strings).nNumUsed--; - ZCSG(interned_strings).nNumOfElements--; - - nIndex = p->h | ZCSG(interned_strings).nTableMask; - if (HT_HASH(&ZCSG(interned_strings), nIndex) == HT_IDX_TO_HASH(idx)) { - HT_HASH(&ZCSG(interned_strings), nIndex) = Z_NEXT(p->val); - } else { - uint32_t prev = HT_HASH(&ZCSG(interned_strings), nIndex); - while (Z_NEXT(HT_HASH_TO_BUCKET(&ZCSG(interned_strings), prev)->val) != idx) { - prev = Z_NEXT(HT_HASH_TO_BUCKET(&ZCSG(interned_strings), prev)->val); - } - Z_NEXT(HT_HASH_TO_BUCKET(&ZCSG(interned_strings), prev)->val) = Z_NEXT(p->val); - } + if (EXPECTED(ZCSG(interned_strings_top) > ZCSG(interned_strings_saved_top))) { + memset(ZCSG(interned_strings_saved_top),0, ZCSG(interned_strings_top) - ZCSG(interned_strings_saved_top)); + ZCSG(interned_strings_top) = ZCSG(interned_strings_saved_top); + while (idx > 0) { + idx--; + p = ZCSG(interned_strings).arData + idx; + if ((char*)p->key < ZCSG(interned_strings_top)) break; + ZCSG(interned_strings).nNumUsed--; + ZCSG(interned_strings).nNumOfElements--; + + nIndex = p->h | ZCSG(interned_strings).nTableMask; + if (HT_HASH(&ZCSG(interned_strings), nIndex) == HT_IDX_TO_HASH(idx)) { + HT_HASH(&ZCSG(interned_strings), nIndex) = Z_NEXT(p->val); + } else { + uint32_t prev = HT_HASH(&ZCSG(interned_strings), nIndex); + while (Z_NEXT(HT_HASH_TO_BUCKET(&ZCSG(interned_strings), prev)->val) != idx) { + prev = Z_NEXT(HT_HASH_TO_BUCKET(&ZCSG(interned_strings), prev)->val); + } + Z_NEXT(HT_HASH_TO_BUCKET(&ZCSG(interned_strings), prev)->val) = Z_NEXT(p->val); + } + } } }