Facing an issue in excel sheet & CSV reader with large quantities of records in Codeignitor.
A PHP Error was encountered
Severity: Warning
Message: simplexml_load_string(): Memory allocation failed : growing buffer
Filename: Reader/Excel2007.php
Line Number: 645
Backtrace:
File: \application\third_party\PHPExcel\Reader\Excel2007.php
Line: 645
Function: simplexml_load_string
File: \application\controllers\admin\Csv.php
Line: 56
Function: load
File: \index.php
Line: 322
Function: require_once
The first option is to increase memory for php with the setting in the file php.ini.
memory_limit = 256M
The number can be lower and different but should be at least higher then it's now, but surely it can be higher than 256M too.
After the change perhaps the sever has to be restarted (depends on some things).
If that doesn't help, then it's worth it to look at the application and even the CSV-file.
Basic problem concerning most frameworks is that data are collected, hold in memory, parsed and then the results are shown or written in the database if applying.
Programs for big data have somehow to chunk the data and that also can mean just to streamline and processing step by step (like a video or soundfile).
As XMLis no stream-format but requires a fully parsed structure before it's processed usually the hint might look a bit useless. But perhaps there are a few things you could do to reduce the data-amount to be processed at once:
If simplexml is used to process several files at once it should be easy just to reduce the amount of files.
if the XML-file(s) are just too large you've to produce smaller files. It's also possible to split files but a little bit knowledge about XML is required for it.
In general it's possible that small tweaks at the implementation in CodeIgniter could solve the problem already, but as that one is unknown here we can only guess about it.
To increase PHP memory limit setting, edit your PHP.ini file. Simply increase the default value (example: Maximum amount of memory a script may consume = 128MB) of the PHP memory limit line in php.ini.
memory_limit = 256M
Alternatively you can edit your .htaccess file.
php_value memory_limit 256M
Note: If you don’t have access to these files or lack the experience to make this change, you can contact your web host and ask them to increase your PHP memory limit.
Related
I'm a system administrator which handles a server that hosts an internal api created using Laravel 5. The data source is a SQL Server hosted on another server and the api is used in a IOS app for mobile phones. When the developers created the api, this error was not present and no other memory errors were found. When we went live this error has been popping up from time to time.
[2015-06-01 23:01:52] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Out of memory (allocated 262144) (tried to allocate 140189808036120 bytes)' in Unknown:0
I checked RAM, CPU, swap etc etc of the server but everything was ok. Not much of the resources are being consumed. I've checked PHP Memory limit from php.ini and is set to -1 which is the max according to PHP. I've checked it on CLI, phpinfo.php and httpd.conf I don't see anything wrong. The team tried following this link Allowed memory size of X bytes exhausted
This is a problem in the ios app because the app searches for a correct return code but when this error comes out, even if the ios app transaction is correct, it returns an error because the return code is incorrect as it is returning the code for the memory error.
The first thing I could think of was to restart the Apache httpd service. This immediately solved the issue. but I knew this is not a permanent fix for the issue. When I researched further, I got to know that the error comes when certain PHP scripts require more memory than PHP was allowed by default.
So the solution is to increase the memory allocated for PHP. How to do that? There are 4 possible ways –
Try looking for the php.ini file. You might find some redundant php.ini files, so make sure you have got the one which is actually being read by PHP. o be sure, create a new php file in your root folder, say “check.php” and have phpInfo(); within the php open and close tags. Execute this file to get the information on where the php.ini is residing. Normally it will be in /usr/local/lib/php.ini
Open the php.ini file in a text editor like TextPad (not in Notepad) and change the values for memory_limit. By default you should see memory_limit = 8M. Try changing it to 12M. If it doesn’t work, increase it to 16M or even 24M and so on.
In case you can’t find the php.ini file or do not have access to it, then open up the file which was throwing the error (admin.php in my case) and add a line below just after ini_set(’memory_limit’, ‘12M’);
You can even consider adding a line in .htaccess file which will resolve the issue.
php_value memory_limit 32M
Or else, Try adding this line to your php file:
Increasing memory allocated to PHP
ini_set(“memory_limit”,”16M“);
I'm using PHP Smarty templates for a website. I noticed that one Smarty based JS file was failing to load today. At first I thought it was a syntax error, but was able to reduce it down to it failing when it exceeded a certain file size limit.
To be exact, if the file size exceeds 109049 bytes for me, the smarty page will not load. So at or below that it is fine, and if I type a single extra character and save, it does not. It comes up empty and the compiled smarty php file is also near empty.
Is there an upper limit, or could it be exceeding some php memory limit somewhere? The file is about 2990 lines long, and is my largest Smarty tpl file by size.
EDIT:
Updating the PHP error reporting didn't help, but adding these two smarty lines did:
$smarty->debugging = true;
$smarty->error_reporting = E_ALL;
Which give some smarty debugging info below. The "memory_limit" is being exceeded. I tried to raise it from 512MB default to basically infinity (10GB), but it always exceeds it.
Why would it be consuming infinite memory?
Fatal error: Out of memory (allocated 2059141120) (tried to allocate 175325 bytes) in /domain.com/lib/Smarty/libs/plugins/modifier.debug_print_var.php on line 36
I have set my PHP MAMP server to a maximum of "256M" in the php.ini but am suddenly getting a memory error. There are two things that are strange about this:
This is a shockingly high amount of memory for a script to use. Maybe I'm too easily shocked but should scripts be running over 256M? I wouldn't have thought so.
Even though I've now changed my setting to "512M" I still get the memory error and it still reports running out in/around the 256M range (as if my setting is being ignored). I did recycle the web server which I figured would be enough to get the new settings into play.
The exact message I'm getting is this:
[25-Oct-2012 14:27:53] PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 222300161 bytes) in [FILE_PATH]/wp-content/themes/lifegadget-pagelines/sections/lg_content/section.php on line 42
[25-Oct-2012 14:27:53] PHP Fatal error: Call to a member function get() on a non-object in [FILE_PATH]/wp-content/object-cache.php on line 52
So my questions are as follows:
Troubleshooting. Is there any way to troubleshoot memory usage?
Scale. Is exceeding a 256M limit a clear problem or is this justified in some cases?
New Ceiling. Why is my new ceiling of 512M being ignored? Not that I'm happy to have it stay at 512M but I would have thought it would at least get me back up and running (I have 16GB on the machine so there's plenty of physical memory).
Infinite loop can cause this or if you have circular references with pre 5.3 PHP version. See: Garbage collection
Inject this function ini_set('memory_limit', -1); at the very beginning of your suspected memory leaking class/page, this is a temporary solution to get things working but it won't help you know where exactly your script is leaking memory.
For some reason, on occasion, I get the following fatal error from my PHP code when running on a shared server:
Fatal error: Maximum execution time of 30 seconds exceeded in C:\HostingSpaces[username][subdomain]\wwwroot\index.php on line 8
And that line is just:
session_regenerate_id();
Might this problem be from the code being hosted on a shared server and resources not being available? Or is there some other cause for this problem?
Since it's a shared server, I can't change any PHP settings.
EDIT:
The only line before line 8 are a few require_once lines for model objects. The only other line is session_start().
I checked my PHP settings and it states that the session.save_handler is files for both the local and master values. Since it is using files, might the problem be trying to read and write from the disk?
I think your problem might be a performance and resource issue as you suspect, but I find it strange that it has only stopped on line 8. I'd guess that the chances could be high if the rest of the code was very minimal.
Have you tried altering the code in an attempt to get the timeout to occur on a different line? For instance, you could try adding sleep(25); and see if the fatal timeout occurs on that line instead.
Also, are you certain that you cannot set the maximum execution time limit? I would suspect that even if you cannot alter the shared php.ini, you could set the max_execution_time through one of these other options:
Setting a php_value max_execution_time directive in an .htaccess
file
Using set_time_limit in your code
Using ini_set and max_execution_time in your code
I believe the value/argument for max_execution_time is in seconds, and if you set it to 0 (zero) then NO execution time limit will be used. (Whether you consider it safe to use zero or not is up to you.)
I've got a script that's giving me headaches on a particular server.
I keep getting this error:
Fatal error: Allowed memory size of 67108864 bytes exhausted
Even though I've edited php.ini to this:
max_execution_time = 300 ; Maximum execution time of each script, in seconds
max_input_time = 600 ; Maximum amount of time each script may spend parsing request data
memory_limit = 96M ; Maximum amount of memory a script may consume (16MB)
Where would the 67108864 bytes limit be coming from?
First, as far as I know, it has to be 96M (without the B)
Second, make sure you are editing the correct php.ini, and you are restarting the web server after the change (needed if PHP is loaded as an apache module for example).
And third, increasing the memory limit may resolve the problem, but it's best to check why 64M are not enough :)
Did you restart apache? Sometimes it's necessary.
I faced a similar issue. It might be because you're storing something very huge in some variable or selecting a lot of data from your mySQL table. You need to provide more information about your script because 64M is really sufficient to execute most of the processing.
By reading the comments, it's obvious you're on a shared hosting account.
Those usually don't let you edit your own php.ini, nor allow arbitrary limits to your pleasing. This would quickly take down the shared hosting server.