Memory Limit in PHP

AID: 294
  • Status: Published

5320 points

  • By
  • TypeGeneral
  • Posted on2008-11-24 at 04:05:58
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

<?php
      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

<?php
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).
Asked On
2008-11-24 at 04:05:58ID294
Tags

memory_limit

,

php memory issues

,

clear memory php

,

Allowed memory size

Topic

PHP Scripting Language

Views
4686

Comments

Expert Comment

by: rdivilbiss on 2010-04-19 at 16:28:30ID: 13484

reviewed rdivilbiss PE

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top PHP Experts

  1. Ray_Paseur

    1,273,020

    Genius

    12,748 points yesterday

    Profile
    Rank: Savant
  2. DaveBaldwin

    274,651

    Guru

    1,668 points yesterday

    Profile
    Rank: Genius
  3. StingRaY

    134,254

    Master

    0 points yesterday

    Profile
    Rank: Wizard
  4. jason1178

    127,552

    Master

    5,000 points yesterday

    Profile
    Rank: Genius
  5. bportlock

    116,923

    Master

    8,000 points yesterday

    Profile
    Rank: Genius
  6. Roads_Roads

    106,350

    Master

    0 points yesterday

    Profile
    Rank: Genius
  7. ChrisStanyon

    99,036

    Master

    0 points yesterday

    Profile
    Rank: Sage
  8. maeltar

    93,247

    Master

    0 points yesterday

    Profile
    Rank: Guru
  9. gr8gonzo

    80,918

    Master

    8,000 points yesterday

    Profile
    Rank: Sage
  10. smadeira

    80,788

    Master

    0 points yesterday

    Profile
    Rank: Wizard
  11. Slick812

    74,566

    Master

    0 points yesterday

    Profile
    Rank: Sage
  12. COBOLdinosaur

    65,841

    Master

    664 points yesterday

    Profile
    Rank: Genius
  13. logudotcom

    65,500

    Master

    1,000 points yesterday

    Profile
    Rank: Genius
  14. johanntagle

    60,700

    Master

    0 points yesterday

    Profile
    Rank: Sage
  15. leakim971

    58,449

    Master

    0 points yesterday

    Profile
    Rank: Genius
  16. un1x86

    54,738

    Master

    1,500 points yesterday

    Profile
    Rank: Master
  17. marqusG

    44,025

    0 points yesterday

    Profile
    Rank: Sage
  18. Derokorian

    43,713

    10 points yesterday

    Profile
    Rank: Guru
  19. DrDamnit

    42,892

    0 points yesterday

    Profile
    Rank: Genius
  20. ahoffmann

    40,068

    0 points yesterday

    Profile
    Rank: Genius
  21. maestropsm

    37,678

    0 points yesterday

    Profile
    Rank: Guru
  22. designatedinitializer

    37,600

    0 points yesterday

    Profile
    Rank: Master
  23. TerryAtOpus

    33,000

    2,000 points yesterday

    Profile
    Rank: Genius
  24. xterm

    32,850

    0 points yesterday

    Profile
    Rank: Sage
  25. eriksmtka

    31,342

    0 points yesterday

    Profile
    Rank: Master

Hall Of Fame