The memory_limit directive in PHP controls the maximum amount of memory a script can allocate. By default, this value is set to 128 MB. On ruachost.com, you can increase or decrease this limit depending on your application’s requirements.
Why Change the Memory Limit?
-
Prevents “Allowed memory size exhausted” errors when running large scripts.
-
Supports applications that process big files, images, or complex database queries.
-
Helps optimize performance by balancing memory usage and server stability.
Methods to Change memory_limit
1. Using a Custom php.ini File
Create or edit a php.ini file in your application directory:
memory_limit = 256M
This sets the maximum memory allocation to 256 MB.
2. Using .user.ini
If your hosting environment supports .user.ini, add:
memory_limit = 256M
3. Using .htaccess
On Apache servers, you can override the directive:
php_value memory_limit 256M
4. Using cPanel (CageFS Enabled Accounts)
-
Log in to cPanel.
-
Go to Software → Select PHP Version → Options tab.
-
Locate
memory_limit. -
Set the desired value (e.g., 256M, 512M).
-
Save changes.
Best Practices
-
Increase gradually (e.g., 256M → 512M) instead of setting excessively high values.
-
Avoid setting unlimited memory (
-1) unless absolutely necessary, as it can destabilize the server. -
Monitor application performance after changes to ensure stability.