Installing and upgrading help

Strategy to Find Moodle Memory Leaking Scripts?

Picture of Paul L
Strategy to Find Moodle Memory Leaking Scripts?

I'm trying to find the source of what may well be a memory leak for a moodle script (php fatal error memory exhaustion (currently set to 512mb)) and was looking for advice on best strategies to find the moodle script that is leaking.

The php fatal error log starts with one (and a few typically follow immediately) particular script 3/4 times (cache\stores\static\lib.php on line 261), 1/4 of the time a couple other scripts start though(lib\classes\component.php on line 1040 , lib\dml\moodle_database.php on line 921) . I am wondering if there are scripts upstream causing the problem and I only see scripts affected by the leaking scripts.

I tried manually reviewing error logs upstream of the fatal error but haven't found any culprit yet.

Does anyone have a better strategy to find php memory leaks in moodle?

I'm reluctant to raise the php_memory limit from 512, do any other moodle admins set this value higher (ie 1GB)? Can courses 1-2GB potentially require a lot of memory to justify the increase?


windows 2008r2/php71/moodle3.3.6+, windows 2008r2/MySQL ,

Average of ratings: -
Picture of Howard Miller
Re: Strategy to Find Moodle Memory Leaking Scripts?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

I can't see you needing more than 512MB for normal use.

Given that it appears to be just you that's having this problem - and PHP isn't inherently bad for memory leaks (if that's what it is), what are you doing that's unusual? In particular, if you are using non-core plugins or themes, especially unusual ones, get rid of them. This has to be the most likely culprit. 

Does it happen when you do something in particular? Can you reliably reproduce it?

I would also simply upgrade Moodle. With problems like these it's a much better idea to be expending your effort with the latest versions. And you might get lucky - it might be fixed. 

It's very difficult tracking down memory issues in PHP. 

Average of ratings: -
Picture of Paul L
Re: Strategy to Find Moodle Memory Leaking Scripts?

I have not duplicated the error but will focus my attack on plugins as the potential source, in particular one we recently removed (see below), thanks for the advice.

Im using version 3.3.6+ which is fairly current and upgrading to 3.4 is difficult to do on short notice at our institution, but will consider it if a disaster occurs in the fall when load increasing 5-10x.

Can I mitigate a memory leak by reducing the following php.ini setting, would this kill a runaway process?
max_execution_time =600
I made it a little higher than usual as I thought large course backups and restores required this. If I reduced this value (600->120) could I potentially discover the script causing the memory exhaustion as the script timing out will be indicated in the php error logs?

We do have a few plugins and recently removed a troublesome one. Here's our list of additional plugins, most of them are pretty standard/popular:

activity modules: h5p, completion progress, course module navigation,
filter: on demand media
admin tools: inspire analytics (php predictor, python predictor)
repositories: on demand
theme: essential

We did remove a Blackboard Collaborate Elluminate block plugin and disabled the activity module after encountering some issue with it after our recent upgrade from 3.1->3.3.6+ , module: elluminate (disabled), missing from disk.

I am concerned older courses which had the blackboard plugins (or are restored to new courses) may be causing some issues as the following errors are fairly common and Im guessing its related to the removed and deleted plugin:
Default exception handler: Can not find data record in database table context. Debug: SELECT * FROM {context} WHERE id = ?
[array (
  0 => ######,

None of the fatal error messages mention elluminate. We do get a lot of non fatal errors mentioning elluminate table does not exist like: Default exception handler: Table "elluminate" does not exist Debug: Error code: ddltablenotexist

I'll try to focus on duplicating the problem with courses that had the blackboard plugins previously.

thanks again.

Average of ratings: -
Picture of Howard Miller
Re: Strategy to Find Moodle Memory Leaking Scripts?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

Setting the execution time will not make a difference. That would only apply if something were sitting in a loop consuming memory. While that's not impossible it's unlikely and, anyway, you would expect the code to consistently fail within that loop and be logged as such. 

I strongly advise you to remove ALL optional plugins from your site. Just remove the code, don't delete them. The data will remain but they cannot be run (the code isn't there). If that fixes your problem then you have, at least, narrowed it down. The next step is to add them back one at a time until it breaks. 

Average of ratings: Useful (2)