App crashing frequently throws "500" error - PHP Fatal error: Allowed memory size of 134217728 bytes exhausted
-
my Shaarli app on Cloudron frequently throws 500 while loading the frontend.
everytime this occurs I see this in Shaarli log:Mar 04 14:40:58 [Tue Mar 04 13:40:58.352043 2025] [php:error] [pid 46] [client 172.18.0.1:36306] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 9235624 bytes) in /app/code/application/bookmark/BookmarkIO.php on line 93
I tried to increase the memory limit via Cloudron allocated resources and php.ini without improvement.
I've also opened an issue in Shaarli repo: https://github.com/shaarli/Shaarli/issues/2130 because this I/O intensive operation for loading such a small DB (9K links) is unbelievable.
I know CLoudron hardcodes this memory limit : https://git.cloudron.io/packages/shaarli-app/-/blob/master/Dockerfile?ref_type=heads#L31 so I first thought that my changes made to php.ini were not taken into account. I wonder also how to double check if those are really taken into account?Yet I also notice that Shaarli codebase contains a init.php file that hardcodes the memory limit to 128M : https://github.com/shaarli/Shaarli/blob/master/init.php#L18 so I also wonder if Cloudron php.ini makes sense.
Thanks for your help!
-
@SansGuidon I can update PHP to 8.3 and see if that helps.
One angle is: shaarli runs with a memory limit at container level. apache spins out processes and each of this has a php limit. It is possible that if apache spins say 5 processes, then 5*128MB > container limit . So, can you try adjusting the app memory limit to say 800MB and checking if that helps ? If that's the case, we can also adjust the package to use a better default memory limit.
-
Thank you @girish
I've already pushed the memory limit up to 1G yesterday without help
What I did try is to edit php.ini with something likedisable_functions = ini_set auto_prepend_file = /app/data/init.php
and the
init.php
was a custom hack looking like<?php $original_ini_set = 'ini_set'; function ini_set($option, $value) { if ($option === 'memory_limit') { return false; } return call_user_func_array($GLOBALS['original_ini_set'], func_get_args()); } call_user_func($original_ini_set, 'memory_limit', '512M'); error_log("Prepend file loaded and memory_limit set to " . ini_get('memory_limit'));
I don't recall all the different versions of the setting I've tried as it was passed midnight but at some point I could work around the hardcoded memory limit of 128M as defined in Shaarli init.php. Yet that didn't solve the root cause
but even if I could see an effective increase of memory limit used by Shaarli at runtime, so completely ignoring what was hardcoded in init.php , that didn't improve the situation
-
@girish thanks for the package update, it might have improved the stability as despite sress testing the shaarli app after updating I didn't face the same error as before. I consider that if this resolves the problem it is a big victory, yet I prefer to not jump to conclusions for now, a good night is needed it the problem is not solved, I should soon get new alerts. Otherwise then I'll mark the issue as solved (hopefully)