Issue
I'm copying/migrating a production server Cakephp 2.3.8 project into a development one but I get the famous error:
Blockquote Fatal Error Error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 200648563 bytes) File: /var/www/html/lib/Cake/Utility/String.php Line: 243
Notice: If you want to customize this error message, create app/View/Errors/fatal_error.ctp
I have already mirror the same specs that the production server:
- Tried to increase the default memory limit on apache > php.ini file from 128M to 1024
- Also 1024 to 2048, but no luck
- Restarted the server and apache service
- Limit the data set on my database (currently have 6, but the production server has about 40K rows on the table that I'm querying)
- Tested a function inside the controller to just display a single line of text (successfully displays it, but the Fatal error message keeps showing up).
This mostly happens when I visit certain controllers because I'm able to load some pages correctly (apparently).
I'm currently debugging the behavior of the app on the log files:
- /ppp/tmp/logs/error.log
- Xdebug
But none of them shows more details that the Fatal error limit, I was told that it might be a memory leak, buy how come if both servers are limited the same way ? (ulimit for servers below).
I would like to know what the problem is, I'm I missing a setting? How could I adjust a Controller in a way to run without errors?
Dev server specs
- Centos 7
- PHP 5.4.16 (cli) (built: Apr 1 2020 04:07:17)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.7, Copyright (c) 2002-2015, by Derick Rethans - VPS on Linode: 2 cores 4 GB of RAM
- Ulimit:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 15076
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 15076
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Production server
- Centos 7
- PHP 5.4.16 (cli) (built: Apr 1 2020 04:07:17)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies - Dedicated server: 16 cores (32 threads), 128Gb of RAM
- Ulimit:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 514324
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 8192
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 8192
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Thanks in advance
UPDATE 1
This is what it shows up after copying lib/Cake/View/Errors/fatal_error.ctp to app/View/Errors/fatal_error.ctp and adding
<pre><?php echo h($error->getTraceAsString()); ?></pre>
Fatal Error Error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 126212148 bytes) File: /var/www/html/lib/Cake/Utility/String.php Line: 243
Notice: If you want to customize this error message, create app/View/Errors/fatal_error.ctp
July 9th '20 Update
#0 /var/www/html/lib/Cake/Error/ErrorHandler.php(184): ErrorHandler::handleFatalError(1, 'Allowed memory ...', '/var/www/html/l...', 243)
#1 [internal function]: ErrorHandler::handleError(1, 'Allowed memory ...', '/var/www/html/l...', 243, Array)
#2 /var/www/html/lib/Cake/Core/App.php(931): call_user_func('ErrorHandler::h...', 1, 'Allowed memory ...', '/var/www/html/l...', 243, Array)
#3 /var/www/html/lib/Cake/Core/App.php(904): App::_checkFatalError()
#4 [internal function]: App::shutdown()
#5 {main}
Before that I was taking out some Components and helpers:
var $helpers=array("Js","Html","Form","Paginator","Fck","Cache","Pagination");
var $components=array("Customcomponent","Paginator","RequestHandler","Cookie","Pagination","Email");
But no luck (got same error message), my other Controller that works doesn't use helpers, only the following components:
var $components=array("Customcomponent","RequestHandler","Cookie","Email","Pagination","Paginator");
Solution
It is unclear what called String.php Line: 243
, full callstack might help
Copy lib/Cake/View/Errors/fatal_error.ctp
to app/View/Errors/fatal_error.ctp
and add
<pre><?php echo h($error->getTraceAsString()); ?></pre>
Answered By - Edgaras JanuĊĦauskas Answer Checked By - Gilberto Lyons (WPSolving Admin)