PHP Memory Directives Relationship

PHP Memory Directives Relationship

I recently had to templatize PHP configurations using Ansible and Jinja2. I had to do some research to ensure that the memory directives that were being defined were actually valid. The three directives I was tinkering with were:

  1. memory_limit
  2. upload_max_filesize
  3. post_max_size

These three directives values' are actually tied together. memory_limit is the max amount of memory that a script can consume. upload_max_filesize defines the largest size a file upload can be. post_max_size limits the max size of post data.

It's not until you read the documentation on post_max_size that it is clearly laid out that these three directives are related:

This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. Generally speaking, memory_limit should be larger than post_max_size.

To summarize, memory_limit must be greater than post_max_size and if your uploading files with a POST method post_max_size should be greater than upload_max_filesize.

post_max_size > upload_max_filesize
memory_limit > post_max_size

Or...

memory_limit > post_max_size > upload_max_filesize

Or...

PHP Memory Relationships

Chris Short

Chris Short

https://chrisshort.net

View Comments