dev > backend sheet (php)

PHP

Use the latest version

Use the PHP-FPM handler

Use opcache

OPcache improves PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.

https://www.php.net/manual/en/book.opcache.php

  • note : you must restart php-fpm after updating your project code so It might have a downtime of the backend for few seconds.

Use app caching ?

  • A DB request is always the same in frontend, ie. no filters, search ...
  • CPU heavy load : image resize, tables joins / databases

Queues

Queue are the best way to defer an operation in a non blocking way for the user.

Use queues when something take more time than a db request :

  • the response is not needed immediately

For example :

  • update a map position by user adress using an API call
  • send notification after a change