What is the PHP memory_limit?

PHP memory_limit – This is the maximum amount of memory that can be used by each PHP script on the server. You can read all about it in the official php docs. “This sets the maximum amount of memory (in bytes) that a script may allocate. This means that poorly written scripts won’t use up all the memory on …”

Why is Memory_limit Important?

memory_limit is the maximum amount of RAM a PHP script can use while it is running. This is important because if there is no limit, one script might take a lot of server resources and affect the other websites or services that are running on the same server.

How Does It Work

When a PHP script runs it asks the server for memory for doing the following:

If script size exceeds memory_limit, PHP will kill the script and generate a fatal error.

Sample Situation

If memory_limit is 128M a script can use 128 megabytes of memory. If it tries to use more than that, it will fail with out of memory error.

Shared Values

Below are some common values you might see:

The right value depends on the type of application you are using.

Conclusion

The PHP memory_limit is one of the most important configuration settings that guarantees stability and performance within a hosting environment. It manages memory per script, allowing the server to stay stable and preventing individual scripts from degrading the overall system performance.