Home > Article > Backend Development > What to do if php has insufficient memory
The solution to insufficient php memory is to increase the maximum memory size of php. Specific method: [ini_set('memory_limit', '16M')]. The ini_set() function is used to set the value of php.ini, which takes effect when the function is executed. The setting becomes invalid after the script ends.
Analysis of the reasons for insufficient memory:
It may be that the php page consumes too much memory. The maximum memory of php is 8M by default.
(Recommended tutorial: php tutorial)
Solution:
Just change the memory size.
Specific method:
Method one:
1. Open the php.ini configuration file;
2. Change the memory_limit from 8M to 16M (or Larger);
3. Just restart the apache service.
Method 2:
Add the following code in the PHP file:
ini_set('memory_limit', '16M');
Function introduction:
PHP ini_set is used to set the value of php.ini. It takes effect when the function is executed. After the script ends, the setting becomes invalid. You can modify the configuration without opening the php.ini file, which is very convenient for virtual spaces.
Function format:
string ini_set(string $varname, string $newvalue)
Note: For the normal use of other resources in the system, please do not set the value of memory_limit too large.
The above is the detailed content of What to do if php has insufficient memory. For more information, please follow other related articles on the PHP Chinese website!