- The CLI sapi is using a different ini file. Make sure you optimize both the web and CLI one.
- Scan your php.ini for best security practices with PHP iniscan tool.
Save system resources by adjusting the memory_limit
value. Don't know what an appropriate value would be? Ask yourself these questions:
- what is the total amount of memory that you can allocate for PHP?
- 512mb should a reasonable amount for a 2gb machine)
- how much memory on average, is consumed by a single process?
- check with
memory_get_peak_usage()
, this is often between 5-20mb
- check with
- how many PHP-processes can I afford?
- if you have 512mb of memory allocated and each process takes 15mb, you can afford 34 processes
Do you have enough system resources? (stress-test with Apache Bench or Siege before you go into production.
Configure the Zend OPcache (php 5.5.0+)
- depending on application size, adjust
opcache.memory_consumption
: 16mb for small apps and 64 for large ones - bump
opcache.interned_strings_buffer
(pointer buffer of identical strings) from 4mb to 16mb - make sure that
opcache.max_accelerated_files
is larger than the number of files in your application - disable
opcache.validate_timestampts
for production, but keep it enabled for development - set
opcache.revalidate_freq
to 0, making sure that PHP checks compiled files for changes on every request during development - turn on
opcache.fast_shutdown
by setting 1 which delegates object deconstruction
Don't use file uploads? set file_uploads
to 0 in order to improve security
You do?
- set a maximum upload filesize that your application accepts and maximum number of uploads that your application accepts at one time.
- bump the
upload_max_filesize
setting to 10mb or higher according to the requirements - adjust the
client_max_body_size
in your nginx virtual host in addition to php.ini
- bump the
Set max_execution_time
from 30 to 5.
Change the default session handler to a faster in-memory data store (like memcached or redis), eliminating unnecessary file I/O with a bonus of enabling future scalability. Be sure to change the session.save_handler
.
Change implicit_flush
to false and make sure output_buffering
is a multiple of 4 (32-bit system) or 8 (64-bit system).
Change the realpath_cache_size
(cache of files so PHP does not have to search the include path) accordingly.
- check by bumping to 256k and then calling
realpath_cache_size()
.