Home  >  Article  >  Backend Development  >  Various methods to modify memory_limit in PHP_PHP tutorial

Various methods to modify memory_limit in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:59:511268browse

I think everyone will know from English that this parameter of memory_limit is a problem of maximum memory. The default is generally 128MB. If we want to make it larger, we have to deal with it ourselves. Let’s take a look at several solutions.

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

Put this script on your web server and call it in the browser. At this time you can see the information about your PHP environment configuration. One of the project groups is about "memory_limit", as shown below:

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

How much should memory_limit be set to?

This is completely dependent on your application's request. For example, WordPress requires 32MB to run the core code. Drupal 6 requires this value to be at least 16MB, and recommends setting it to 32MB. If you install a lot of plug-ins, especially those modules that require image processing, then you may need 128MB or higher memory.

How to set memory_limit

Method 1: php.ini

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

1. First find the php.ini file that is valid for your website. Because there are multiple places where you can set php parameters, finding the correct configuration file and making changes is the first step. If you created a php file in the above method 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 modifying php.ini in your php installation directory.

2. Edit php.ini In php.ini, find the "memory_limit" item. If not, you can add this parameter yourself at the end of the file. Here are some sample settings

memory_limit = 128M; You can change 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 privately. For example, if you purchased a virtual hosting service, your service provider does not allow you to modify this file. Then, you may need to consider using other methods to increase the value of memory_limit.

Method 2: .htaccess

Note: This method only takes effect when php is executed as an Apache module. Find the ".htaccess" file in the root directory of your website. If it doesn't exist, you can create one yourself. Then put the following equipment into this

php_value memory_limit 128M; You can change 128M to any value you want to set

Method 3: Modify php’s memory settings at runtime

Just add the following command line to your php code.

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631286.htmlTechArticleI think everyone will know that the parameter memory_limit is a problem of maximum memory if you read it in English. The default is generally 128MB if you want to change it. We have to take care of it ourselves. Here are some solutions...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn