What's limiting my PHP resources? - php

I'm having a problem getting more memory out of PHP.
This is the error message:
Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 82 bytes) in ...
Yet:
I've set memory_limit in the php.ini file to 32M:
memory_limit = 32M;
I've also tried to override it manually in the actual script:
ini_set('memory_limit', '32M');
And -- here's where I'm lost -- I've confirmed via phpinfo() that this php.ini file is the actual ini file used, and the memory_limit seems to be set correctly. The line on memory_limit gives this:
memory_limit 32M 32M
So it would seem that everything is configured properly, but I'm only getting 20971520 bytes (~20M).
Where else should I be looking to figure out where this limitation is being imposed?
EDIT: I'm running php under nginx/fastcgi, on Ubuntu 9.04 in a VPS. The php-cgi processes do seem to be a bit resource-hungry (RES=25m, VIRT=187m), but I have 10m of physical memory free and 500m of swap space free.

My first instinct is to guess that PHP is reading a different php.ini.
In Debian (and most likely Ubuntu), each version of PHP (cli, cgi, and apache) has its own copy of php.ini.

I just pored over the code I was running, and someone had hard-coded this into a config file:
ini_set('memory_limit', '20M');
Which was overriding everything else I was doing. Whew.

You could try setting it in the .htaccess file, that is what i had to do to get a site working on one server.
here are the settings i used:
php_value upload_max_filesize 50M
php_value post_max_size 60M
php_value memory_limit 128M

Related

PHP Error - keep getting "Out of memory error"

I kept getting this error on one of the site Im working on
Message Out of memory (allocated 2097152) (tried to allocate 20480 bytes)
and the thing is we already set the memory limit to 512MB, and seems weird that it says allocated 2097152 which is like only 2MB?
This site is running in wordpress with woocommerce, and the even woocommerce status says the memory limit is 512MB.
Can anybody explain whats going on?
Server is running on NGINX + PHP-FPM
Try set upload_max_filesize, post_max_size , max_file_uploads and memory_limit in php.ini and then restart your Apache server. If it did not work, try to set the mentioned parameters to right on top of your code.
Best way to increase memory limit in PHP or WordPress.
Via php.ini file
memory_limit 2048M
post_max_size 200M
upload_max_filesize 20M
max_file_uploads 20
Via PHP script
ini_set('memory_limit','2048M');
ini_set('post_max_size','200M');
ini_set('upload_max_filesize','20M');
ini_set('max_file_uploads','20');
Via wp_config.php file in WordPress
define('WP_MEMORY_LIMIT', '2048M');
Via htaccess
php_value memory_limit 256M
php_value post_max_size 200M
php_value upload_max_filesize 20M
php_value max_file_uploads 20
In wp-config file Update the memory limit according to your need
define('WP_MEMORY_LIMIT', '256m');
define('WP_MAX_MEMORY_LIMIT', '512m');

PHP Fatal error: Out of memory (allocated 1707606016) (tried to allocate 426680697 bytes)

I have a droplet on DigitalOcean, it was a 10$ package with 1GB Memory, then I upgraded to 20$ package.
So how it all started was that I'm trying to upload a file from one server to another using cURL parameters, now the issue is... The file doesn't send because I get this beautiful error.
PHP Fatal error: Out of memory (allocated 1707606016) (tried to allocate 426680697 bytes)
Now I have memory_limit set to 2048MB because that's how much MB of memory I got on my VPS. Now before I upgraded, I had only 1024MB of memory and the error message was different at the time, and this is what I got.
PHP Fatal error: Out of memory (allocated 530055168) (tried to allocate 529639729 bytes)
My VPS has MORE than enough memory to upload a 403MB file, and I have my memory_limit maxed, there's no way I need to upgrade the servers memory limit.
memory_limit = 2048M
file_uploads = On
upload_max_filesize = 5000M
max_file_uploads = 20
allow_url_fopen = On
post_max_size = 0
max_execution_time = 90000
max_input_time = 90000
Obviously it may look like a duplicate, but the solutions on all of the posts I've looked at don't work for me. The script that is having its memory_limit is literally a handler that handles the cURL request sent from the alternative server.
You can changed the php.ini
memory_limit = -1
and add to httpd.conf And restart Apache
I had the same issue in a DigitalOcean droplet of 1GB of RAM and 1CPU.
Trying to install two differents LMS systems, Claroline and Chamilo. I upgraded the droplet to 2GB of RAM and same CPU.
The issue was solved. Deffintively it was something related to memmory limits.
You can changed the php.ini
memory_limit = 128M
and add to httpd.conf
And restart and restart apache

uploading files greater than 8 mb in php

Warning: POST Content-Length of 11313557 bytes exceeds the limit of
8388608 bytes
I am getting this above warning. I searched around internet and I have also increased the the following limits in php.ini:
max_input_time = 600000;
max_execution_time = 60000000;
file_uploads = On;
upload_max_filesize = 1000M;
post_max_size = 1000M;
and also in mysql.ini file i have changed
max_allowed_packet = 100M;
but still I get the following warning. Files less than 8mb are easily uploaded but greater than 8mb pops up the above error message.
You need to set the value of upload_max_filesize and post_max_size in your php.ini :
; Maximum allowed size for uploaded files.
upload_max_filesize = 40M
; Must be greater than or equal to upload_max_filesize
post_max_size = 40M
And then you should stop your apache service and then start your apache.
In case of linux based systems
/opt/lampp/lampp stop
/opt/lampp/lampp start
In case of windows just stop and stop your apache or your xampp service.
Check the phpinfo page and see you have edited the correct configuration file. Loaded configuration file can be found in phpinfo page under Loaded Configuration File
Add as first line at your process file
set_time_limit(0);

How to solve memory limit issue in shared host

i am getting memory limit error while loading some of the pages of my website.
My issue is, i don't have rights to modify memory_limit in php.ini so is there any other way to override this settings ?
I am getting following error.
Fatal error: Allowed memory size of 94371840 bytes exhausted (tried to allocate 122880 bytes) in /xx/xx/xx/plugins/otbcCompanyPlugin/lib/model/om/BaseOtbcCompanyCompanyPeer.php on line 1567
i tried:
ini_set('memory_limit', '512M');
echo ini_get('memory_limit');exit; // prints 90M
And i tried following in .htaccess
<IfModule mod_php5.c>
php_value memory_limit 512m
</IfModule>
and
<IfModule mod_php.c>
php_value memory_limit 512m
</IfModule>
but didn't work.
you can check phpinfo().
so is there anything missed by me ?
I have encountered the same issue. But it's pretty easy:
cPanel > section Software/Services > Select PHP Version menu.
Click on Switch to PHP extensions and there you will see the option for raising the php memory limit as memory_limit.
In some hosts, you can configure the custom php.ini file from here too.
you can try to add your owen php.ini file in wich you specify :
memory_limit = 512M
to do so :
create a php.ini file in your root folder
add memory_limit = 512M
create .htaccess file and add this line :
SetEnv PHPRC /home/username/folder/php.ini
this will load your custom instructions in your php.ini
to make sure just run the
<?php phpinfo() ?>

PHP memory_limit locked to 256MB?

I am trying to set memory_limit to 512M, but it's locekd to 256M.
ini_set('memory_limit','512M');
ini_get('memory_limit'); //> Returns: 256M
I have full control on my server. (it's a dedicated)
Please note that everything under 512M works.
ini_set('memory_limit','16M');
ini_get('memory_limit'); //> Returns: 16M
Solution
I found out why. in php.ini I had memory_limit = 256M. Maybe this is considered as an upper limit
3 possibles I can think of / find:
Prior to PHP 5.2.1, in order to use this directive it had to be
enabled at compile time by using --enable-memory-limit in the
configure line.
OR
The issue detailed here: ini_set("memory_limit") in PHP 5.3.3 is not working at all
OR
ini_set is disabled
You can also try to change the memory_limit using either a php.ini or .htaccess file
php.ini
memory_limit = 512M;
.htaccess
php_value memory_limit 512M
A bit late in the day but editing the php.ini file didn't work for php 7.1 using Mac OS 10.11.6. I still kept on getting the 'PHP Fatal error: Allowed memory size of....' which from its value showed the memory setting was not updating after starting apache.
So instead of editing the file.
/usr/local/php5/lib/php.ini
I found changing the following file fixed this issue.
/usr/local/php5/php.d/99-liip-developer.ini
This file was actually replacing the values set in the initial php.ini file. Again making the following changes to the line...
memory_limit = 256M
to
memory_limit = 1024M
And restarting apache.
sudo /usr/sbin/apachectl restart
I noticed that on my Mac (OS X El Capitan) and the new PHP 7.0.0, I cannot change memory_limit via php.ini
But I can change it via /etc/apache2/httpd.conf by adding the line in the end:
php_value memory_limit 1024M
and restarting apache server:
sudo apachectl restart
And it is the correct php.ini , I can change other settings via it.
You could check in your php.ini config file at the directive called "disable_functions". Check if ini_set is disabled.
Also if safe_mode is enabled such option may not be overriden.
I found out why. in php.ini I had memory_limit = 256M. Maybe this is considered as an upper limit.
I rised it to my need.

Categories