Bug #78076 [NEW]: Opcache greatly increases memory usage.

From: Date: Mon, 27 May 2019 21:25:07 +0000
Subject: Bug #78076 [NEW]: Opcache greatly increases memory usage.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-221019@lists.php.net to get a copy of this message
From:             tyler dot bannister at remote-learner dot net
Operating system: Centos 7.4.1708
PHP version:      7.1.29
Package:          opcache
Bug Type:         Bug
Bug description:Opcache greatly increases memory usage.

Description:
------------
Using the database install script for Moodle 3.2, 3.3, 3.4, 3.5 or
Totara 10, 11 or 12 with PHP 7.1.28 or 7.1.29 when opcache is turned on
the script runs out of memory even if the memory limit is increased to 2
GB, when opcache is turned off the script uses 78 MB of memory, when
opcache is turned on it ran out of memory with 2 GB of memory allowed,
at 4 GB of memory the script was killed before it could complete but it
looked like it was using all of that memory before it was killed.

I suspect that issue is that during installation the Moodle install
script does something incredibly stupid, it turns off caching of
language strings (it's multi-language system) which means every time it
needs to print a message it includes the file that contains the string. 
Over the course of the database install it ends up including each file
hundreds of times and with or without opcache enabled each of those
includes seems to increase the amount of memory used, but with opcache
enabled the memory usage grows much faster.

I've written a pair of simple test scripts to illustrate this behaviour.

Test script:
---------------
test1.php:
<?php
print("Starting Memory:". memory_get_usage() ."\n");
for ($x = 1; $x < 10000; $x += 1) {
    include("test2.php");
}
print("Ending Memory:". memory_get_usage() ."\n");

test2.php:
<?php
$a = "Hello World!\n";


Expected result:
----------------
When test1.php and test2.php are placed in the same directory and the
scrits are run with opcache enabled and opcache disabled they should
produce roughly the same starting and ending memory sizes.


Actual result:
--------------
Opcache disabled:
Starting Memory:349712
Ending Memory:349872

Opcache enabled:
Starting Memory:348856
Ending Memory:7820120


-- 
Edit bug report at https://bugs.php.net/bug.php?id=78076&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=78076&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=78076&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=78076&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=78076&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=78076&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=78076&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=78076&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=78076&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=78076&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=78076&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=78076&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=78076&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=78076&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=78076&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=78076&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=78076&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=78076&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78076&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=78076&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=78076&r=mysqlcfg



Thread (11 messages)

« previous php.bugs (#221019) next »