memorylimit
Read or set PHP
memory_limit(the most memory one script may use; default -1, unlimited) across all php.ini files, then reload PHP-FPM a minute later
- Command:
/go/memorylimit - Category: PHP
- Required option: None. With no value, it sets
-1(no limit). - Output: Plain text
- Last updated: 2026-11-20
On this page: Overview · Quick start · Syntax · Options · Output · Examples · Troubleshooting · Details · See also
Overview
/go/memorylimit sets PHP's memory_limit in the php.ini file of every installed PHP version at once. This is the most memory a single PHP script may use while it runs. The command:
- finds the php.ini files for the PHP-FPM, command-line, and Apache versions of each installed PHP version
- replaces the existing
memory_limitline, or adds one if there is none - schedules a PHP-FPM reload one minute later, so the new value takes effect without further steps
- can also print the current value instead of changing it
[!WARNING] With no value, the command sets
-1, which means no limit. A single faulty or heavily used script can then use all of the server's memory. Prefer an explicit value, such as/go/memorylimit 512M.
Quick start
# Set a limit of 512 MB per script in every php.ini
/go/memorylimit 512M
The new value is live about a minute later.
Syntax
/go/memorylimit [value]
/go/memorylimit return
| Form | Behavior |
|---|---|
/go/memorylimit |
Sets memory_limit = -1 (no limit) in every php.ini file. |
/go/memorylimit <value> |
Sets that value in every php.ini file. |
/go/memorylimit return |
Prints the current value and changes nothing. The word is not case-sensitive. |
If the first argument starts with -- (for example --force), it is ignored and -1 is set.
Options
This command has no options. It takes one optional argument.
| Argument | Required | Default | Notes |
|---|---|---|---|
<value> |
No | -1 |
A size with a unit, or -1. Nothing checks the value (see Validation). |
return |
No | — | Prints the current value instead of setting one. |
Accepted size formats:
| Value | Meaning |
|---|---|
256M |
256 megabytes |
1G |
1 gigabyte |
-1 |
No limit |
512 |
512 bytes. A number without K, M, or G is a number of bytes, so every PHP script will fail. Always add the unit. |
PHP's own default is 128M.
Output
| Outcome | What you get |
|---|---|
| Value set | Memory Limit updated successfully. |
return |
The value from the first php.ini found. Blank if that file has no memory_limit line. |
| Unsupported operating system | Unknown operating system. Nothing is changed. |
The success message is printed even if no php.ini file was found, so it does not prove that anything changed. Check with return.
The scheduled reload prints nothing. Every run is also recorded in /var/log/go/memorylimit.log.
[!NOTE]
returnends with exit status1, andreturndoes not schedule a reload. In scripts, read the output instead of relying on the exit status.
Examples
# Allow 256 MB per script
/go/memorylimit 256M
# Allow 1 GB per script
/go/memorylimit 1G
# Remove the limit (use with care)
/go/memorylimit -1
# Show the current value
/go/memorylimit return
# Apply the change immediately instead of waiting for the scheduled reload
/go/memorylimit 512M && /go/fpm
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Every PHP page fails with Allowed memory size of 512 bytes exhausted (or a similarly tiny number) |
The value was passed without a unit. | Run /go/memorylimit 512M. |
Allowed memory size of ... bytes exhausted on a heavy page |
The limit is too low for that script. | Raise the value. |
| The server runs out of memory under load | The limit is -1, or many PHP workers each use a lot of memory. |
Set an explicit limit and check mem. |
The old value still shows in phpinfo() right after the command |
The PHP-FPM reload is scheduled for one minute later. | Wait a minute, or run fpm now. |
| The value is still old after several minutes | The reload is scheduled with at. If at isn't installed or its service isn't running, the job fails silently. |
Install at and start its service, then run /go/fpm reload. |
| A site on Apache with mod_php still uses the old value | The scheduled reload covers PHP-FPM only. | Reload the web server, for example with web. |
| A site uses a different value | A setting for that site (for example in its PHP-FPM pool or a .user.ini file) or the application itself (such as WordPress's memory setting) can override php.ini. |
Change it where it is set. |
return prints nothing |
The first php.ini has no memory_limit line starting at the beginning of a line. |
Run /go/memorylimit <value> to add it. |
return shows a different value than one version uses |
return reports only the first php.ini file found. |
Open the other versions' php.ini files to compare. |
Unknown operating system. |
The operating system name in /usr/local/goadmio/linux/os.db isn't one the script knows. |
The script supports AlmaLinux, Rocky, CentOS, Red Hat, Fedora, Debian, and Ubuntu. |
Permission denied |
The command was not run as root. Adding a missing line writes to the file without sudo. |
Run it as root. |
| PHP reports a syntax error in php.ini after a change | Several words were passed and written as is. | Run /go/memorylimit <value> again with one value, or use checkphpini. |
| Success message, but no file changed | No php.ini files exist at the expected paths. | Check the paths in Files it changes. |
Details
Files it changes
The script reads the operating system from /usr/local/goadmio/linux/os.db. Only files that exist are changed.
| Operating system | Files |
|---|---|
| AlmaLinux, Rocky, CentOS, Red Hat, Fedora | /etc/php.ini, and /etc/opt/remi/<version>/php.ini for each version found |
| Debian, Ubuntu | /etc/php.ini, and for each version in /etc/php/: <version>/fpm/php.ini, <version>/cli/php.ini, and <version>/apache2/php.ini |
How a value is written
For each php.ini file:
| Situation | Result |
|---|---|
An uncommented memory_limit = line exists |
Every such line is replaced with memory_limit = <value>. |
The setting is missing, or only exists as a comment (;memory_limit = 128M) |
A new memory_limit = <value> line is added at the end of the file. |
If the file's last line has no trailing newline, the added line may be joined to it. Check the file if PHP reports an error after the change.
Validation
The command does not check the value. Everything after the command name is written as typed, so 512 1G or abc ends up in php.ini as is. Pass a single value with a unit.
Memory limit and total memory
The limit applies to each script, not to the whole server. With PHP-FPM, many workers can run at once, so the memory they can use together is roughly the number of workers times the limit. Choose a value your server can afford under load.
The scheduled reload
After the files are changed, the command checks the queue of scheduled jobs (atq). If no /go/fpm reload job is already waiting, it schedules /go/fpm reload to run one minute later.
- Running the command several times within a minute schedules only one reload.
- A queued job such as a plain
/go/fpmis not recognized, so a second reload may still be scheduled. - The job is created silently. Errors from
atare not shown. - Run the command as root, so the queue check sees every user's jobs.
What it does not change
- PHP-FPM pool settings and values set inside applications.
- The server's own memory limits for users. See
slice. max_execution_time, which limits how long a script runs. Seemaxexecutiontime.
See also
| Command | Description |
|---|---|
maxexecutiontime |
Change the max execution time for all PHP versions |
postmaxsize |
Read or set PHP post_max_size across all php.ini files |
uploadmaxfilesize |
Read or set PHP upload_max_filesize across all php.ini files |
mem |
Check the top ten memory-consuming commands or services |
slice |
Apply server-wide CPU and memory limits to user-.slice |
checkphpini |
Scan every php.ini on the server for startup errors and delete the line that causes each one |
fpm |
Restart all installed PHP-FPM versions on your server |