How to increase memory limit for PHP over 2GB?
Have you tried using the value in MB ?
php_value memory_limit 2048M
Also try editing this value in php.ini
not Apache.
Increasing PHP memory_limit. At what point does it become insane?
The configuration for the memory_limit
of PHP running as an Apache module to server webpages has to take into consideration how many Apache process you can have at the same time on the machine -- see the MaxClients
configuration option for Apache.
If MaxClients
is 100 and you have 2,000 MB of RAM, a very quick calculation will show that you should not use more than 20 MB *(because 20 MB * 100 clients = 2 GB or RAM, ie the total amount of memory your server has)* for the memory_limit value.
And this is without considering that there are probably other things running on the same server, like MySQL, the system itself, ... And that Apache is probably already using some memory for itself.
Or course, this is also a "worst case scenario", that considers that each PHP page is using the maximum amount of memory it can.
In your case, if you need such a big amount of memory for only one job, I would not increase the memory_limit
for PḦP running as an Apache module.
Instead, I would launch that job from command-line (or via a cron job), and specify a higher memory_limit
specificaly in this one and only case.
This can be done with the -d
option of php, like :
$ php -d memory_limit=1GB temp.php
string(3) "1GB"
Considering, in this case, that temp.php only contains :
var_dump(ini_get('memory_limit'));
In my opinion, this is way safer than increasing the memory_limit for the PHP module for Apache -- and it's what I usually do when I have a large dataset, or some really heavy stuff I cannot optimize or paginate.
If you need to define several values for the PHP CLI execution, you can also tell it to use another configuration file, instead of the default php.ini, with the -c
option :
php -c /etc/phpcli.ini temp.php
That way, you have :
/etc/php.ini
for Apache, with lowmemory_limit
, lowmax_execution_time
, ...- and
/etc/phpcli.ini
for batches run from command-line, with virtually no limit
This ensures your batches will be able to run -- and you'll still have security for your website (memory_limit
and max_execution_time
being security measures)
Still, if you have the time to optimize your script, you should ; for instance, in that kind of situation where you have to deal with lots of data, pagination is a must-have ;-)
PHP: Does ini_set(memory_limit,1024M); implicitly relase memory resources on PHP script execution end?
ini_set
Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.
Need to say anything more? Yes one thing! Garbage collection has nothing to do with the ini_set
calls that you have. Both are 2 different things.
Increase memory limit
Ok thanks to all I just need to set memory_limit = 94G in dompdf class and now it is creating large pdf but after some minutes browser says "The connection was reset - The connection to the server was reset while the page was loading. etc...." although I increase the execution time up to 3600 sec //ini_set('max_execution_time', 3600)
About PHP’s memory usage
«Out of memory» messages (not to be confused with «Allowed memory size exhausted» ones) always indicate that the PHP interpreter literally ran out of memory. There's no PHP or Apache setting you can tweak—the computer is just no able to feed PHP with more RAM. Common causes include:
- Scripts that use too much memory.
- Memory leaks or bugs in the PHP interpreter.
SimpleXML is a by no means a lightweight extension. On the contrary, its easy of use and handy features come at a cost: high resource consumption. Even without seeing a single line of code, I can assure that SimpleXML is totally unsuitable to create an XML file with 30,000 items. A PHP script that uses 2GB of RAM can only take down the whole server.
Nobody likes changing a base library in the middle of a project but you'll eventually need to do so. PHP provides a pull parser called XMLWriter. It's really not much harder to use and it provides two benefits:
- It's way less resource intensive, since it doesn't create the complex object that SimpleXML uses.
- You can flush partial results to file.
- Can even write to file directly.
With it, I'm sure your 2 GB script can run with a few MB.
increase site speed by increasing memory limit?
You can call an override function to change memory limit localy on the application just call this at the top of your php file:
ini_set('memory_limit', '64M'); //change 64M to whatever you like...
OR change it globaly in php.ini (in xampp located in '\xampp\php\php.ini'):
memory_limit = 8M // search for this "memory_limit" and adjust it by your needs.
After that restart apache...
- But in my experience memory load problems are more connected with execution of MySQL queries then running php scripts alone. CPU load also, almost always connected with badly written queries.
Also 512mb is realy low ammount for a serious web server.
Related Topics
PHP How to Get the Base Domain/Url
How to Use Two Submit Buttons, and Differentiate Between Which One Was Used to Submit the Form
Simple Comet Example Using PHP and Jquery
How to Use PHP in a JavaScript Function
Using Laravel Socialite to Login to Facebook
Select Within 20 Kilometers Based on Latitude/Longitude
Inserting Now() into Database with Codeigniter's Active Record
PHP Datetime Microseconds Always Returns 0
How to Install an Older Version of PHPunit Through Pear
How to Access a Different Controller from Inside a Controller Symfony2
PHP Dom Get Nodevalue HTML? (Without Stripping Tags)
Secure User Image Upload Capabilities in PHP
How to Determine If Pdo Is Enabled in PHP
A PHP/Pthreads Thread Class Can't Use Array