<

Memory Limit in PHP

Published on
11,176 Points
7,776 Views
4 Endorsements
Last Modified:
Loganathan Natarajan
LAMP Developer, PHP Expert, Web Developer
Some times, we may experience memory related issues like Fatal error: Allowed memory size of 567745 bytes exhausted or even out of memory. These errors occur because of limiting the memory to utilize more from the web server. It is a common issue in the shared hosting type web sites.

To resolve this issue, you may need to change the memory_limit variable value in the php.ini. As default it may be 8MB or 16MB. It can be increased temporarily as 20MB or depending on the size of your web site

You can view the memory allotted to use for your site by creating phpinfo.php file with


      echo phpinfo();
?>

just look at the memory_limit variable how much it is allotted. now you can modify the memory_limit with the following options:

Option -- 1 - Change the memory_limit from php.ini
On your server, edit the php.ini file and find the memory_limit variable configuration and change the value. After the change, you need to restart the server. This change will applicable as entire sites running on the server.

If you are using shared hosting, you cannot access the php.ini file do this change.
 

Option -- 2 - Change the memory_limit using .htaccess
You can also do this change temporarily using .htaccess file placing on your site root directory

.htaccess
php_value memory_limit 20M

place this file on the root directory of your site and check the memory value gets updated.
 

Option -- 3 - Change the memory_limit in your php file script
It is a custom change on your php script for your use to achieve the purpose. You can just specify the memory limit amount and use it on your site.

To do this, your php might have been compiled with the --enable-memory-limit configure option


ini_set("memory_limit","20M");

< & your php code follows &>
      
?>

It is better to clear all the variables after we don't need them any more in the site using unset($variable).
4
Comment
3 Comments
LVL 29

Expert Comment

by:rdivilbiss
reviewed rdivilbiss PE
0

Expert Comment

by:Eduardo Fuerte
Very good!

Our site is actually using 128M and due a large download using Codeigniter force_download it's needing 1024 MB...
0
LVL 36

Author Comment

by:Loganathan Natarajan
it's needing 1024 MB...

it depends on your computer RAM, system configuration etc.,
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Join & Write a Comment

The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month