Modify PHP's Memory_limit limit method to share _php tips

Source: Internet
Author: User
Tags save file hosting
To solve this problem, first need to see if your program is allocating too much memory, in the case of the program is not a problem, you can use the method to increase the PHP memory limit (memory_limit).

Check PHP for Memory limits

To view this value, you need to create an empty PHP file, such as view-php-info.php. Then put the code inside.

<?php phpinfo ();?>

Put this script on your Web server and call it in the browser. At this point you can see your PHP environment configuration information, part of which is about "Memory_limit", the following figure:

Note: You can use this method to view other PHP parameter settings, not just Memory_limit

How much should the Memory_limit be set?

This depends entirely on the requirements of your application. For example, WordPress, running the core code requires 32MB. Drupal 6 requires this value to be a minimum of 16MB and is recommended to be set to 32MB. If you install a lot of plug-ins (plugins), especially those that want to do image processing, then you may need 128MB or higher memory.

How to set up Memory_limit

Method 1:php.ini

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

1. First find the php.ini file for your site because there are multiple places to set PHP parameters, find the correct configuration file, and make changes is the first step. If the above method creates a PHP file to view its configuration parameters, you can find the item "Loaded Configuration file", and here's an example:

For Linux users, you can perform "php-i | grep Loaded Configuration file "to find the corresponding configuration file. and Windows users, you can try to modify your PHP installation directory under the php.ini.

2. Edit PHP.ini in php.ini, find "Memory_limit", if not, you can add this parameter at the end of the file. Here are some examples of settings

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

Save File

3. Restart the Web server if the Web server uses Apache, execute:

httpd restart

In some cases, you may not be allowed to modify php.ini in private. For example, if you buy a virtual hosting service, your provider does prohibit you from modifying the file. Then you may need to consider other ways to increase the value of memory_limit.

Method 2:. htaccess

Description: This method only takes effect when PHP is executed in the Apache module. Locate the ". htaccess" file in the root directory of your Web site, and if not, create one yourself. Then put the following configuration into it

Php_value Memory_limit 128M; You can change the 128M to any value you want to set

Method 3: Modify the PHP memory settings at run time

Add the following command line to your PHP code.

Ini_set (' Memory_limit ', ' 128M ');

Memory_limit modification failed

If you use a virtual host, there may be a Memory_limit value modification failure. This needs to be contacted by your service provider to see how it is handled, usually by limiting the maximum size that can be set or not allowing you to modify it at all. If their environment really doesn't meet your requirements, then you might want to consider a different hosting 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.