Category: PHP

PHP user.ini file

If you don’t know already, I am obsessed with optimising everything around me, including PHP. Today, I am going to share a tip to optimise PHP, particularly PHP-FPM. It assumes that you do not use “.user.ini” file or you never heard about it. ūüėČ

As per the official docs for .user.ini file, by default, PHP scans each user directory for the file named “.user.ini”¬†for every 5 minutes. So, it is much¬†better than what Apache does to .htaccess files. Still, if you don’t use it, just disable it in the php.ini file. Just set “user_ini.filename” as empty in php.ini of your PHP-FPM process. To make it easier, the default php.ini file already contains the line commented out. So, uncommenting is enough to disable “.user.ini” functionality and make your server a bit more snappier!

Stay tuned for further optimisation tips!

Advertisements

Display Active Conf in php-fpm pool

Php-fpm pool configuration contains 400+ lines (for example in Ubuntu 16.04). In reality, we may use only about 20 lines or less than 5% of the file. The original configuration file contains lines that explains what each config does. It is good practice to have inline documentation.

In certain cases, we may want to know what¬†lines are actually¬†active. To find that please use the following command…

grep -v '^;\|^$' /path/to/fpm/pool.d/www.conf

What it does:

The ‘-v’ modifier excludes the pattern that immediately follows it.

The quoted string has two parts.

  1. ‘^;’ excludes any lines that do not start with a semi-colon.
  2. ‘^$’ excludes the empty lines

‘|’ modifier combines the above two parts. Finally, ‘\’ modifier is the escape character.

Remove PHP Sessions

At times, due to mis-configuration or a bug, the session data may not have been removed automatically by PHP cron. So, use the following to remove all the sessions files…

find /var/lib/php/ -name "sess_*" -print -delete