How to modify the memory_limit limit of php

Source: Internet
Author: User
When running a PHP program, you usually encounter the error "FatalError: Allowedmemorysizeofxxxxxxbytesexhausted". This means that the PHP script uses too much memory and exceeds the maximum memory allowed by the system. When running the PHP program, the Error "Fatal Error: Allowed memory size of xxxxxx bytes exhausted" usually occurs. This means that the PHP script uses too much memory, the maximum memory allowed by the system is exceeded.

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.

 

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:

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 and find "memory_limit" in php. ini. 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.