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.