20th June 2022

Separate your slow back-end from important front-end traffic with PHP-FPM

Let's see some tricks on how to create two PHP process queues, one for the frontend and one for the backend.

Backend Frontend

If you are using WordPress, WooCommerce, Magento, Shopware, Oxid, a CMS or any other standard software, usually both the frontend and the backend use the same application fpm pool. Even for self-developed applications with Symfony or other frameworks this is often the case.

The backend / administrator can therefore include many slow operations, administrative operations and data exports that can take a long time. This could congest the web servers' processing queue reducing throughput for your customers who might just click the payment button and see a 502 Bad Gateway error.

Putting frontends and backends on different physical servers is a solution, but it can be too expensive for most use cases as we are effectively doubling the costs for the two machines or instances.

PHP-FPM Pool separation between frontend and backend

An effective solution to avoid bottlenecks in web applications is to configure Separate PHP-FPM pools for frontend and backend, each with distinct parameters for managing requests and resources.

To understand the concept, imagine running a bar with only one shared bathroom between customers and employees. At certain times, such as during a crowded party, you may find yourself with a long line: the customer has to wait for the employee to finish, and vice versa. This generates inefficiencies and poor service, slowing down staff work and worsening the customer experience.

It is for this reason that many places adopt a practical division: separate bathrooms for customers and staff, so as to avoid interference and conflicts of use.

Similarly, even in the server environment, it is useful Don't mix frontend and backend in the same PHP-FPM poolOperations performed by the backend—often slower and more intensive, such as report exports or administrative processing—can saturate resources and slow down responses to frontend requests, which are instead related to the user experience (page loading, checkout, login, etc.).

By separating the two environments into separate pools, it is ensured that slow backend operations do not block frontend user traffic, improving stability, responsiveness and overall quality of service.

Magento administration and frontend example

How does it look? Let's use Magento as an example, you can set up two pools in php-fpm.conf:

; php-fpm.conf [frontend] listen = /var/run/php-fpm-frontend.sock pm = static pm.max_children = 50 [backend] listen = /var/run/php-fpm-backend.sock pm = ondemand pm.max_children = 5 pm.process_idle_timeout = 5

The frontend is configured for up to 50 concurrent requests and the backend for up to 5 concurrent requests. Back-end workers are created on demand and front-end workers are static to avoid fork overhead. I will discuss the differences between PHP-FPM pool configurations in a future blog post.

You can then change the Nginx vhost configuration for Magento installation with the following switch:

server { # More server directives... set $fpm_socket "unix:/var/run/php-fpm-frontend.sock"; if ($uri ~* "^/admin/") { set $fpm_socket "unix:/var/run/php-fpm-backend.sock"; } location ~ \.php$ { # Other FastCGI directives... include fastcgi_params; fastcgi_pass $fpm_socket; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }

Based on the ^/adminpath in the request uri, it will now select the different PHP FPM pool and the frontend and backend will no longer compete and steal each other's resources.

If instead we were working with WordPress or WooCommerce the path would be ^ / wp-admin.

What matters is obviously the concept behind it, which is the ability to create separate and path-based queues.

 

Do you have doubts? Don't know where to start? Contact us!

We have all the answers to your questions to help you make the right choice.

Chat with us

Chat directly with our presales support.

0256569681

Contact us by phone during office hours 9:30 - 19:30

Contact us online

Open a request directly in the contact area.

DISCLAIMER, Legal Notes and Copyright. RedHat, Inc. holds the rights to Red Hat®, RHEL®, RedHat Linux®, and CentOS®; AlmaLinux™ is a trademark of the AlmaLinux OS Foundation; Rocky Linux® is a registered trademark of the Rocky Linux Foundation; SUSE® is a registered trademark of SUSE LLC; Canonical Ltd. holds the rights to Ubuntu®; Software in the Public Interest, Inc. holds the rights to Debian®; Linus Torvalds holds the rights to Linux®; FreeBSD® is a registered trademark of The FreeBSD Foundation; NetBSD® is a registered trademark of The NetBSD Foundation; OpenBSD® is a registered trademark of Theo de Raadt; Oracle Corporation holds the rights to Oracle®, MySQL®, MyRocks®, VirtualBox®, and ZFS®; Percona® is a registered trademark of Percona LLC; MariaDB® is a registered trademark of MariaDB Corporation Ab; PostgreSQL® is a registered trademark of PostgreSQL Global Development Group; SQLite® is a registered trademark of Hipp, Wyrick & Company, Inc.; KeyDB® is a registered trademark of EQ Alpha Technology Ltd.; Typesense® is a registered trademark of Typesense Inc.; REDIS® is a registered trademark of Redis Labs Ltd; F5 Networks, Inc. owns the rights to NGINX® and NGINX Plus®; Varnish® is a registered trademark of Varnish Software AB; HAProxy® is a registered trademark of HAProxy Technologies LLC; Traefik® is a registered trademark of Traefik Labs; Envoy® is a registered trademark of CNCF; Adobe Inc. owns the rights to Magento®; PrestaShop® is a registered trademark of PrestaShop SA; OpenCart® is a registered trademark of OpenCart Limited; Automattic Inc. holds the rights to WordPress®, WooCommerce®, and JetPack®; Open Source Matters, Inc. owns the rights to Joomla®; Dries Buytaert owns the rights to Drupal®; Shopify® is a registered trademark of Shopify Inc.; BigCommerce® is a registered trademark of BigCommerce Pty. Ltd.; TYPO3® is a registered trademark of the TYPO3 Association; Ghost® is a registered trademark of the Ghost Foundation; Amazon Web Services, Inc. owns the rights to AWS® and Amazon SES®; Google LLC owns the rights to Google Cloud™, Chrome™, and Google Kubernetes Engine™; Alibaba Cloud® is a registered trademark of Alibaba Group Holding Limited; DigitalOcean® is a registered trademark of DigitalOcean, LLC; Linode® is a registered trademark of Linode, LLC; Vultr® is a registered trademark of The Constant Company, LLC; Akamai® is a registered trademark of Akamai Technologies, Inc.; Fastly® is a registered trademark of Fastly, Inc.; Let's Encrypt® is a registered trademark of the Internet Security Research Group; Microsoft Corporation owns the rights to Microsoft®, Azure®, Windows®, Office®, and Internet Explorer®; Mozilla Foundation owns the rights to Firefox®; Apache® is a registered trademark of The Apache Software Foundation; Apache Tomcat® is a registered trademark of The Apache Software Foundation; PHP® is a registered trademark of the PHP Group; Docker® is a registered trademark of Docker, Inc.; Kubernetes® is a registered trademark of The Linux Foundation; OpenShift® is a registered trademark of Red Hat, Inc.; Podman® is a registered trademark of Red Hat, Inc.; Proxmox® is a registered trademark of Proxmox Server Solutions GmbH; VMware® is a registered trademark of Broadcom Inc.; CloudFlare® is a registered trademark of Cloudflare, Inc.; NETSCOUT® is a registered trademark of NETSCOUT Systems Inc.; ElasticSearch®, LogStash®, and Kibana® are registered trademarks of Elastic NV; Grafana® is a registered trademark of Grafana Labs; Prometheus® is a registered trademark of The Linux Foundation; Zabbix® is a registered trademark of Zabbix LLC; Datadog® is a registered trademark of Datadog, Inc.; Ceph® is a registered trademark of Red Hat, Inc.; MinIO® is a registered trademark of MinIO, Inc.; Mailgun® is a registered trademark of Mailgun Technologies, Inc.; SendGrid® is a registered trademark of Twilio Inc.; Postmark® is a registered trademark of ActiveCampaign, LLC; cPanel®, LLC owns the rights to cPanel®; Plesk® is a registered trademark of Plesk International GmbH; Hetzner® is a registered trademark of Hetzner Online GmbH; OVHcloud® is a registered trademark of OVH Groupe SAS; Terraform® is a registered trademark of HashiCorp, Inc.; Ansible® is a registered trademark of Red Hat, Inc.; cURL® is a registered trademark of Daniel Stenberg; Facebook®, Inc. owns the rights to Facebook®, Messenger® and Instagram®. This site is not affiliated with, sponsored by, or otherwise associated with any of the above-mentioned entities and does not represent any of these entities in any way. All rights to the brands and product names mentioned are the property of their respective copyright holders. All other trademarks mentioned are the property of their respective registrants.

JUST A MOMENT !

Have you ever wondered if your hosting sucks?

Find out now if your hosting provider is hurting you with a slow website worthy of 1990! Instant results.

Close the CTA
Back to top