How to modify the memory_limit limit of PHP

Source: Internet
Author: User

To solve this problem, first check whether your program has allocated too much memory. If there is no problem with the program, you can use the following method to increase the memory limit (memory_limit) of PHP ).

Check the php memory limit value

To view this value, you need to create an empty PHP file, such as a view-php-info.php. Then paste the code into it.

<? Php phpinfo ();?>

Put the script on your Web server and call it in your browser. At this time, you can see the configuration information of your PHP environment, some of which are about "memory_limit", such:

Note: You can use this method to view other php parameter settings, not just memory_limit

What Should memory_limit be set?

This is totally dependent on your application requirements. For example, Wordpress requires 32 MB to run the core code. Drupal 6 requires a minimum value of 16 MB and is recommended to be set to 32 MB. If you install many plug-ins, especially those that require image processing, you may need MB or higher memory.

How to Set memory_limit

Method 1: php. ini

The simplest or most common method is to modify php. ini.

1. First, find the php. ini file that takes effect for your website. Because php parameters can be set in multiple places, find the correct configuration file and make changes. If the above method creates a PHP File to view its Configuration parameters, you can find the "Loaded Configuration File" item. The following is an example:

For Linux users, you can find the corresponding Configuration File by executing "php-I | grep Loaded Configuration File. For Windows users, you can try to modify the php. ini under your php installation directory.

2. Edit php. ini. in php. ini, find "memory_limit". If not, add this parameter at the end of the file. The following are some configuration examples:

Memory_limit = 128 M; you can change M to any value you want to set.

Save files

3. Restart the web server. If the web server uses Apache, run the following command:

Httpd restart

In some cases, you may not be allowed to modify php. ini. For example, if you have purchased the VM service, but your service provider does not allow you to modify this file. You can use other methods to increase the value of memory_limit.

Method 2:. htaccess

Note: This method takes effect only when php is executed using the Apache module. Find the ". htaccess" file in the root directory of your website. If not, create one by yourself. Then put the following configuration into it:

Php_value memory_limit 128 M; you can change M to any value you want to set.

Method 3: Modify the php memory settings at runtime

Add the following command line to your php code.

Ini_set ('memory _ limit ', '128m ');

Memory_limit modification failed

If you use a VM, you may fail to modify the memory_limit value. You need to contact your service provider to learn how to handle this problem. Generally, they limit the maximum value that can be set or they cannot be modified at all. If their environment does not meet your requirements, you may have to consider changing the host service provider.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.