{"id":3710,"date":"2025-12-29T23:13:08","date_gmt":"2025-12-29T20:13:08","guid":{"rendered":"https:\/\/www.dchost.com\/blog\/isolating-php-session-and-queue-workers-with-php-fpm-supervisor-and-systemd\/"},"modified":"2026-11-04T23:14:02","modified_gmt":"2026-11-04T20:14:02","slug":"php-fpm-session-queue-workers","status":"publish","type":"post","link":"https:\/\/www.dchost.com\/blog\/en\/php-fpm-session-queue-workers\/","title":{"rendered":"PHP-FPM Pools, Sessions and Queue Worker Management"},"content":{"rendered":"<div class=\"dchost-blog-content-wrapper\"><p>On a busy PHP application server, sending all HTTP workloads \u2013 web requests, admin panels, API calls and HTTP-triggered jobs \u2013 to a single PHP\u2011FPM pool can create a bottleneck. Long\u2011running requests occupy PHP\u2011FPM children and can delay other requests. CLI queue workers and cron jobs do not occupy FPM children, but can compete with them for CPU, memory, storage and database capacity. Separating HTTP workloads into PHP\u2011FPM pools and managing CLI workers with Supervisor or systemd lets you tune their concurrency independently.<\/p>\n<p>In this article we\u2019ll walk through a practical process architecture for PHP sites and frameworks like Laravel, Symfony, WordPress and custom apps. We\u2019ll look at why isolation matters, how to separate HTTP workloads into PHP\u2011FPM pools and run CLI queue workers independently, where Supervisor and systemd fit in, and how to choose resource limits to protect checkout latency while heavy jobs run in the background.<\/p>\n<p>Pool separation is a concurrency\/process design, not complete security isolation or a latency guarantee. Same-master pools share OPcache; operating-system budgets need explicitly separate services\/cgroups.<\/p>\n<div id=\"toc_container\" role=\"navigation\" aria-label=\"Table of Contents\" data-nosnippet class=\"toc_transparent no_bullets toc_numbered toc_title_center\"><p class=\"toc_title\">\u0130\u00e7indekiler<\/p><ul class=\"toc_list\"><li><a href=\"#Why_You_Should_Isolate_PHP_Sessions_and_Queue_Workers\"><span class=\"toc_number toc_depth_1\">1.<\/span> Why You Should Isolate PHP Sessions and Queue Workers<\/a><ul><li><a href=\"#The_classic_singlepool_problem\"><span class=\"toc_number toc_depth_2\">1.1.<\/span> The classic single\u2011pool problem<\/a><\/li><li><a href=\"#What_isolation_gives_you_in_practice\"><span class=\"toc_number toc_depth_2\">1.2.<\/span> What isolation gives you in practice<\/a><\/li><\/ul><\/li><li><a href=\"#The_Building_Blocks_PHPFPM_Pools_Supervisor_and_systemd\"><span class=\"toc_number toc_depth_1\">2.<\/span> The Building Blocks: PHP\u2011FPM Pools, Supervisor and systemd<\/a><ul><li><a href=\"#PHPFPM_pools_as_isolation_units\"><span class=\"toc_number toc_depth_2\">2.1.<\/span> PHP\u2011FPM pools as isolation units<\/a><\/li><li><a href=\"#Supervisor_keeping_CLI_workers_alive\"><span class=\"toc_number toc_depth_2\">2.2.<\/span> Supervisor: keeping CLI workers alive<\/a><\/li><li><a href=\"#systemd_units_slices_and_timers\"><span class=\"toc_number toc_depth_2\">2.3.<\/span> systemd: units, slices and timers<\/a><\/li><\/ul><\/li><li><a href=\"#Session_and_Worker_Isolation_Architecture_Patterns\"><span class=\"toc_number toc_depth_1\">3.<\/span> Session and Worker Isolation: Architecture Patterns<\/a><ul><li><a href=\"#Pattern_1_Separate_PHPFPM_web_handling_from_CLI_queue_workers\"><span class=\"toc_number toc_depth_2\">3.1.<\/span> Pattern 1: Separate PHP\u2011FPM web handling from CLI queue workers<\/a><\/li><li><a href=\"#Pattern_2_Isolating_sessionheavy_vs_stateless_traffic\"><span class=\"toc_number toc_depth_2\">3.2.<\/span> Pattern 2: Isolating session\u2011heavy vs stateless traffic<\/a><\/li><li><a href=\"#Pattern_3_Sessions_and_cache_storage_isolation\"><span class=\"toc_number toc_depth_2\">3.3.<\/span> Pattern 3: Sessions and cache storage isolation<\/a><\/li><\/ul><\/li><li><a href=\"#Designing_Web_vs_Worker_Resources_and_Limits\"><span class=\"toc_number toc_depth_1\">4.<\/span> Designing Web vs Worker Resources and Limits<\/a><ul><li><a href=\"#Different_latency_expectations\"><span class=\"toc_number toc_depth_2\">4.1.<\/span> Different latency expectations<\/a><\/li><li><a href=\"#Example_sizing_pools_on_a_4_vCPU_8_GiB_RAM_VPS\"><span class=\"toc_number toc_depth_2\">4.2.<\/span> Example: sizing pools on a 4 vCPU \/ 8 GiB RAM VPS<\/a><\/li><li><a href=\"#Using_systemd_slices_and_priorities\"><span class=\"toc_number toc_depth_2\">4.3.<\/span> Using systemd slices and priorities<\/a><\/li><\/ul><\/li><li><a href=\"#Putting_It_Together_Example_Implementation\"><span class=\"toc_number toc_depth_1\">5.<\/span> Putting It Together: Example Implementation<\/a><ul><li><a href=\"#1_Define_multiple_PHPFPM_pools\"><span class=\"toc_number toc_depth_2\">5.1.<\/span> 1. Define multiple PHP\u2011FPM pools<\/a><\/li><li><a href=\"#2_Route_requests_to_the_right_pool_via_Nginx\"><span class=\"toc_number toc_depth_2\">5.2.<\/span> 2. Route requests to the right pool via Nginx<\/a><\/li><li><a href=\"#3_Configure_queue_workers_with_Supervisor\"><span class=\"toc_number toc_depth_2\">5.3.<\/span> 3. Configure queue workers with Supervisor<\/a><\/li><li><a href=\"#4_Or_run_workers_via_systemd_units\"><span class=\"toc_number toc_depth_2\">5.4.<\/span> 4. Or run workers via systemd units<\/a><\/li><li><a href=\"#5_Observability_separate_logs_and_metrics\"><span class=\"toc_number toc_depth_2\">5.5.<\/span> 5. Observability: separate logs and metrics<\/a><\/li><\/ul><\/li><li><a href=\"#Relating_This_to_PerSite_PHPFPM_Pool_Architecture\"><span class=\"toc_number toc_depth_1\">6.<\/span> Relating This to Per\u2011Site PHP\u2011FPM Pool Architecture<\/a><ul><li><a href=\"#Persite_and_perrole_pools_together\"><span class=\"toc_number toc_depth_2\">6.1.<\/span> Per\u2011site and per\u2011role pools together<\/a><\/li><li><a href=\"#When_to_move_beyond_a_single_server\"><span class=\"toc_number toc_depth_2\">6.2.<\/span> When to move beyond a single server<\/a><\/li><\/ul><\/li><li><a href=\"#Operational_Tips_and_Common_Pitfalls\"><span class=\"toc_number toc_depth_1\">7.<\/span> Operational Tips and Common Pitfalls<\/a><ul><li><a href=\"#Avoiding_deadlocks_and_session_contention\"><span class=\"toc_number toc_depth_2\">7.1.<\/span> Avoiding deadlocks and session contention<\/a><\/li><li><a href=\"#Graceful_deploys_with_queue_and_pool_isolation\"><span class=\"toc_number toc_depth_2\">7.2.<\/span> Graceful deploys with queue and pool isolation<\/a><\/li><li><a href=\"#Testing_before_enabling_in_production\"><span class=\"toc_number toc_depth_2\">7.3.<\/span> Testing before enabling in production<\/a><\/li><\/ul><\/li><li><a href=\"#Keep_HTTP_Capacity_and_CLI_Worker_Budgets_Explicit\"><span class=\"toc_number toc_depth_1\">8.<\/span> Keep HTTP Capacity and CLI Worker Budgets Explicit<\/a><\/li><li><a href=\"#Technical_References\"><span class=\"toc_number toc_depth_1\">9.<\/span> Technical References<\/a><\/li><\/ul><\/div>\n<h2><span id=\"Why_You_Should_Isolate_PHP_Sessions_and_Queue_Workers\">Why You Should Isolate PHP Sessions and Queue Workers<\/span><\/h2>\n<h3><span id=\"The_classic_singlepool_problem\">The classic single\u2011pool problem<\/span><\/h3>\n<p>A common PHP\u2011FPM setup starts with one PHP\u2011FPM pool, one user, one set of limits. Nginx or Apache sends all traffic to the same unix socket or TCP port. At first this is fine, but as soon as you add:<\/p>\n<ul>\n<li>Queued jobs (emails, imports, webhooks, video processing)<\/li>\n<li>Long\u2011running reports or exports from the admin panel<\/li>\n<li>API consumers that can spike traffic at any time<\/li>\n<li>High\u2011value sessions (logged\u2011in customers, admin users)<\/li>\n<\/ul>\n<p>you may see two kinds of contention. A big export handled through FPM can occupy a child while page loads wait for a free one. A CPU\u2011hungry CLI queue worker does not use an FPM child, but can still slow checkout, login and product pages by consuming shared server or database resources.<\/p>\n<h3><span id=\"What_isolation_gives_you_in_practice\">What isolation gives you in practice<\/span><\/h3>\n<p>By separating session\u2011bearing HTTP requests into PHP\u2011FPM pools and running queue workers as independently managed CLI processes, you can gain:<\/p>\n<ul>\n<li><strong>More predictable response times for web sessions<\/strong>: a dedicated pool reserves FPM request capacity for session\u2011bearing traffic, though shared CPU, memory and storage can still become bottlenecks.<\/li>\n<li><strong>Controlled capacity for background jobs<\/strong>: CLI worker concurrency and resource limits can be tuned separately from FPM request capacity.<\/li>\n<li><strong>Cleaner failure domains<\/strong>: a worker crash need not stop HTTP handling, but memory leaks or deadlocks affecting shared resources can still disrupt the site.<\/li>\n<li><strong>Security separation<\/strong>: you can run web pools and CLI workers under different Unix users and assign filesystem permissions accordingly; network restrictions require additional controls.<\/li>\n<li><strong>More accurate tuning<\/strong>: each FPM pool has its own <code>pm.max_children<\/code>, <code>pm.max_requests<\/code>, timeouts and INI settings tuned for its workload.<\/li>\n<\/ul>\n<p>We\u2019ve written before about <a href=\"https:\/\/www.dchost.com\/blog\/en\/laravel-queues-supervisor-systemd-pm2\/\">why background jobs matter so much on a VPS<\/a>; the missing piece for many teams is giving those jobs their own resource \u201clane\u201d instead of mixing them with interactive traffic.<\/p>\n<h2><span id=\"The_Building_Blocks_PHPFPM_Pools_Supervisor_and_systemd\">The Building Blocks: PHP\u2011FPM Pools, Supervisor and systemd<\/span><\/h2>\n<h3><span id=\"PHPFPM_pools_as_isolation_units\">PHP\u2011FPM pools as isolation units<\/span><\/h3>\n<p>At the heart of this architecture are multiple PHP\u2011FPM pools. Each pool groups FPM child processes with its own:<\/p>\n<ul>\n<li>User\/group and actual filesystem grants.<\/li>\n<li>Process-manager settings: pm, max_children and recycling.<\/li>\n<li>Pool-specific INI directives within their supported scope; CLI uses its own configuration.<\/li>\n<li>Separate session_pool\/api_pool sockets. A queue socket is not needed for CLI workers.<\/li>\n<\/ul>\n<p>One possible application layout separates three workload roles; only the HTTP roles use FPM pools:<\/p>\n<ul>\n<li><strong>web<\/strong>: for normal HTTP requests (frontend, API, maybe admin)<\/li>\n<li><strong>session\u2011critical<\/strong>: sometimes a smaller dedicated pool for cart\/checkout or login flows<\/li>\n<li><strong>queue<\/strong>: independently managed CLI worker processes (Laravel queue workers, custom daemons), not an FPM pool<\/li>\n<\/ul>\n<p>For more reading on PHP-FPM tuning, browse the <a href=\"https:\/\/www.dchost.com\/blog\/en\/\">DCHost blog<\/a>. Parameters such as pm.max_children and pm.max_requests apply across PHP workloads, but values must be measured for the application.<\/p>\n<h3><span id=\"Supervisor_keeping_CLI_workers_alive\">Supervisor: keeping CLI workers alive<\/span><\/h3>\n<p><strong>Supervisor<\/strong> is a simple, battle\u2011tested process manager for long\u2011running CLI programs. It\u2019s ideal for things like:<\/p>\n<ul>\n<li><code>php artisan queue:work<\/code> or <code>php artisan horizon<\/code> in Laravel<\/li>\n<li>Symfony Messenger workers<\/li>\n<li>Custom PHP daemons (e.g. websocket bridges, importers)<\/li>\n<\/ul>\n<p>Supervisor handles:<\/p>\n<ul>\n<li>Automatic restart when a worker exits, according to the configured restart policy<\/li>\n<li>Process count (how many workers per queue)<\/li>\n<li>Logging stdout\/stderr to dedicated log files<\/li>\n<\/ul>\n<p>Supervisor is one process-management option; a dedicated instance prevents this queue budget from silently including unrelated programs. Direct systemd units are an alternative.<\/p>\n<h3><span id=\"systemd_units_slices_and_timers\">systemd: units, slices and timers<\/span><\/h3>\n<p>On many modern Linux distributions, <strong>systemd<\/strong> is the init system responsible for services. It gives you:<\/p>\n<ul>\n<li><strong>Service units<\/strong>: to run long\u2011running PHP workers or short\u2011lived scheduler commands as managed services<\/li>\n<li><strong>Resource control<\/strong>: CPU, memory and IO limits using cgroups and slices<\/li>\n<li><strong>Timers<\/strong>: cron\u2011like scheduling of service units; job health checks still need to be designed explicitly<\/li>\n<\/ul>\n<p>You can choose either Supervisor or systemd for managing queue workers; both are valid. A useful division of responsibility is:<\/p>\n<ul>\n<li>PHP\u2011FPM for <strong>short\u2011lived HTTP requests<\/strong><\/li>\n<li>Supervisor or systemd for <strong>long\u2011running CLI workers<\/strong><\/li>\n<\/ul>\n<p>If you\u2019re curious about how systemd timers compare to classic cron for scheduled jobs, we have a separate guide on <a href=\"https:\/\/www.dchost.com\/blog\/en\/cron-vs-systemd-timers-the-friendly-way-to-ship-reliable-schedules-and-real-healthchecks\/\">Cron vs systemd timers and reliable scheduling<\/a>.<\/p>\n<h2><span id=\"Session_and_Worker_Isolation_Architecture_Patterns\">Session and Worker Isolation: Architecture Patterns<\/span><\/h2>\n<h3><span id=\"Pattern_1_Separate_PHPFPM_web_handling_from_CLI_queue_workers\">Pattern 1: Separate PHP\u2011FPM web handling from CLI queue workers<\/span><\/h3>\n<p>Start by distinguishing two execution contexts:<\/p>\n<ul>\n<li><strong><code>[web]<\/code> pool<\/strong> \u2013 handles Nginx\/Apache PHP requests.<\/li>\n<li><strong>CLI queue workers<\/strong> \u2013 run independently of FPM under Supervisor or systemd, with their own PHP configuration and process limits.<\/li>\n<\/ul>\n<p>Implement this \u201cweb pool vs worker context\u201d separation by:<\/p>\n<ul>\n<li>Running PHP\u2011FPM for HTTP traffic only<\/li>\n<li>Running CLI workers with a dedicated php.ini or environment; <code>php -d ... artisan queue:work<\/code> is schematic, with the ellipsis standing for actual INI overrides<\/li>\n<\/ul>\n<p>CLI workers already run outside the pool of FPM children. The remaining task is to bound their resource use so they do not overwhelm the resources shared with web requests.<\/p>\n<h3><span id=\"Pattern_2_Isolating_sessionheavy_vs_stateless_traffic\">Pattern 2: Isolating session\u2011heavy vs stateless traffic<\/span><\/h3>\n<p>In many real projects, not all traffic is equal:<\/p>\n<ul>\n<li>Logged\u2011out product\/category pages can be cached heavily<\/li>\n<li>Logged\u2011in dashboard, cart and checkout depend on per\u2011user data and may use PHP sessions or application\u2011specific session storage<\/li>\n<li>Public API endpoints may be stateless but high\u2011volume<\/li>\n<\/ul>\n<p>You can map these to different FPM pools, for example:<\/p>\n<ul>\n<li><strong>session_pool:<\/strong> session-bearing frontend\/admin requests.<\/li>\n<li><strong>api_pool:<\/strong> API requests whose middleware actually behaves statelessly.<\/li>\n<li>Other per-role pools may be appropriate, but every pool\/master must be counted in the aggregate host budget.<\/li>\n<\/ul>\n<p>Use a defined application entrypoint contract rather than send arbitrary URI prefixes directly to FastCGI. The complete index.php-only example and optional same-host API prefix routing appear below; neither is a drop-in WordPress configuration.<\/p>\n<p>Nginx first selects a prefix, then considers matching regex locations unless an exact or ^~ match terminates that search. The optional \/api\/ prefix deliberately preserves PHP\/dot-path denial rules. Every FastCGI location checks that index.php exists and sends a fixed SCRIPT_FILENAME plus the original REQUEST_URI\/query\/POST parameters.<\/p>\n<p>Correctly routed API requests use a different set of FPM children from session\u2011bearing requests. The pools still share server resources, and separating them does not remove session\u2011store contention.<\/p>\n<h3><span id=\"Pattern_3_Sessions_and_cache_storage_isolation\">Pattern 3: Sessions and cache storage isolation<\/span><\/h3>\n<p>Session storage must follow application state boundaries, independently of pool names. Options include:<\/p>\n<ul>\n<li>Files with permissions shared only by pools serving that application\u2019s native sessions.<\/li>\n<li>Redis with a deliberate data scope and explicit locking\/TTL\/authentication policy.<\/li>\n<li>Memcached where the chosen handler\u2019s persistence, expiration and concurrency semantics fit the application.<\/li>\n<\/ul>\n<p>We covered the trade\u2011offs in detail in our guide on <a href=\"https:\/\/www.dchost.com\/blog\/en\/php-session-cache-files-redis-memcached\/\">choosing PHP session and cache storage (files vs Redis vs Memcached)<\/a>. Isolate session storage between unrelated applications, but keep storage access and expiry settings consistent across pools serving the same application session. Separate databases, key prefixes or namespaces distinguish data; they should not be treated as independent resource budgets or security boundaries.<\/p>\n<p>Pools serving the same native PHP session must share accessible storage, session name, cookie scope, lifetime and GC policy. Otherwise login\/cart state can disappear when routing changes pools. Host-only cookies are not automatically shared across subdomains; choose cookie Domain deliberately. WordPress\/WooCommerce and Laravel session layers are not automatically changed by native PHP INI settings. Laravel normally allows concurrent same-session requests; route blocking is an explicit application choice with an atomic-lock driver and appropriate TTL\/wait settings.<\/p>\n<p>For native file sessions, avoid holding the lock across unnecessary slow work. This runnable PHP example saves state and releases the lock before a synthetic slow step. Later writes to $_SESSION are not automatically persisted after session_write_close. Concurrent application updates still need a consistency design; early unlocking is not safe for every workflow.<\/p>\n<pre class=\"language-php line-numbers\"><code class=\"language-php\">&lt;?php\ndeclare(strict_types=1);\n\nif (!session_start()) {\n    http_response_code(503);\n    exit(&#039;Session unavailable&#039;);\n}\n$_SESSION[&#039;visits&#039;] = (int) ($_SESSION[&#039;visits&#039;] ?? 0) + 1;\n$visits = $_SESSION[&#039;visits&#039;];\nif (!session_write_close()) {\n    http_response_code(503);\n    exit(&#039;Session save failed&#039;);\n}\n\/\/ Perform slow work only after saving and releasing the native session lock.\n\/\/ This synthetic pause is not an application background queue.\nusleep(200000);\nheader(&#039;Content-Type: application\/json&#039;);\necho json_encode([&#039;visits&#039; =&gt; $visits], JSON_THROW_ON_ERROR);\n<\/code><\/pre>\n<p>Redis is a useful optional store, not a guarantee of faster or lock-free requests. PhpRedis 6.2.0 documents session locking as disabled by default and supported for a single-master topology. The optional settings below are for a private local exercise Redis. Production requires its actual ACL\/authentication, TLS where appropriate, access and retention controls. Apply the same settings across pools serving one application; unrelated applications need separate data scope.<\/p>\n<p>This snippet uses PHP INI syntax. Before selecting Redis, verify that PhpRedis is loaded in the FPM context. In both pools, replace the existing <code>php_admin_value[session.save_handler]<\/code> value with <code>redis<\/code> and <code>php_admin_value[session.save_path]<\/code> with the same Redis connection address shown here; changing only the global php.ini while retaining the pool\u2019s <code>files<\/code> and filesystem-path overrides is insufficient. Apply the locking settings in an INI file loaded by FPM. After a controlled reload, verify the effective handler\/storage settings and cross-pool session continuity. Existing file sessions are not automatically imported into Redis; plan migration or deliberate reauthentication.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">session.save_handler = redis\nsession.save_path = &quot;tcp:\/\/127.0.0.1:6379?database=2&amp;prefix=shop_session_&amp;timeout=1&amp;read_timeout=1&quot;\nredis.session.locking_enabled = 1\nredis.session.lock_expire = 90\nredis.session.lock_wait_time = 10000\nredis.session.lock_retries = 100\nsession.gc_maxlifetime = 1440\n<\/code><\/pre>\n<p>lock_expire is seconds and lock_wait_time is microseconds. Here 90 s exceeds the longest 60 s FPM request ceiling; 100 \u00d7 10000 \u00b5s is approximately 1 s of retry waits, excluding network time. Handle failed session_start as a failed request if the lock cannot be acquired. Recheck long blocking I\/O, shutdown behavior and changed timeouts. A Redis database\/prefix separates keys, not resource budgets or authorization. Do not assume this single-master locking recipe applies to RedisCluster\/RedisArray.<\/p>\n<h2><span id=\"Designing_Web_vs_Worker_Resources_and_Limits\">Designing Web vs Worker Resources and Limits<\/span><\/h2>\n<h3><span id=\"Different_latency_expectations\">Different latency expectations<\/span><\/h3>\n<p>Choose latency targets separately for interactive requests and background jobs, then verify them under concurrent load.<\/p>\n<ul>\n<li>Web requests: define a measured latency target for interactive routes such as checkout and login; a few hundred milliseconds can be an example target, not a universal usability threshold.<\/li>\n<li>Queue workers: jobs may take seconds or minutes, provided their own timeout, retry window and business deadline allow it.<\/li>\n<\/ul>\n<p>From this, the tuning approach becomes clearer:<\/p>\n<ul>\n<li>Select HTTP ceilings from actual endpoint behavior; PHP max_execution_time and FPM wall-clock termination are different, and I\/O accounting depends on platform\/build\/version.<\/li>\n<li>Select queue concurrency, per-job timeout and total CPU\/memory budget independently; a longer-running job still needs explicit downstream-I\/O timeouts.<\/li>\n<\/ul>\n<h3><span id=\"Example_sizing_pools_on_a_4_vCPU_8_GiB_RAM_VPS\">Example: sizing pools on a 4 vCPU \/ 8 GiB RAM <a href=\"https:\/\/www.dchost.com\/vps\">VPS<\/a><\/span><\/h3>\n<p>For arithmetic only, suppose the host has 4 vCPUs and 8 GiB RAM. Draft budgets are 4 GiB for this dedicated FPM master, 2 GiB for the queue layer and 2 GiB for OS\/Nginx\/database\/Redis\/other overhead. The final share may be insufficient for your services; measure peaks, page cache and safety margin. A sum equal to installed RAM is not evidence of safe capacity.<\/p>\n<ul>\n<li>session_pool: dynamic, max_children 12, start\/min spare 4, max spare 8.<\/li>\n<li>api_pool: dynamic, max_children 8, start\/min spare 2, max spare 4.<\/li>\n<li>Four CLI queue workers in a single 2 GiB aggregate budget. These are illustrative values, not a recommendation for every 4 vCPU host.<\/li>\n<\/ul>\n<p>Four CPU-heavy workers can saturate four vCPUs without an effective quota. NVMe does not guarantee negligible I\/O contention. Measure HTTP p95\/p99, throttling, queue age, memory and database pressure together. Our <a href=\"https:\/\/www.dchost.com\/blog\/en\/vps-sizing-woocommerce-laravel-nodejs\/\">VPS sizing guide for WooCommerce, Laravel and Node.js<\/a> provides additional context.<\/p>\n<h3><span id=\"Using_systemd_slices_and_priorities\">Using systemd slices and priorities<\/span><\/h3>\n<p>If you run queue workers under systemd, you can use slices and cgroups to enforce priorities. For example:<\/p>\n<ul>\n<li>Place the dedicated FPM master and queue layer in their explicitly named services\/slices.<\/li>\n<li>Use aggregate queue CPU\/memory limits; relative I\/O weights depend on the actual hierarchy\/controller\/scheduler.<\/li>\n<li>Review every other master, pool and service competing on the host; pools do not reserve RAM\/CPU.<\/li>\n<\/ul>\n<p>These settings bound selected workloads but do not guarantee responsive web requests. Shared databases, storage and host pressure remain relevant. If a measured process peak were 80 MiB (session) or 60 MiB (API), 2048 MiB divided by that value gives about 25 or 34 processes before master\/shared\/variance overhead. At 350 MiB per queue worker, 2048\/350 gives about 5 before overhead. Those are arithmetic upper divisions, not safe limits; the smaller 12\/8 and 4 example still needs acceptance tests.<\/p>\n<h2><span id=\"Putting_It_Together_Example_Implementation\">Putting It Together: Example Implementation<\/span><\/h2>\n<h3><span id=\"1_Define_multiple_PHPFPM_pools\">1. Define multiple PHP\u2011FPM pools<\/span><\/h3>\n<p>The concrete example targets Ubuntu 24.04, PHP 8.3 FPM\/CLI, Nginx, systemd and Supervisor 4.2+. Start on a separate test server with a working, backed-up application. <code>\/var\/www\/site\/public\/index.php<\/code> is the only PHP entrypoint in this routing contract. Application dependencies, an existing TLS certificate covering both hostnames, database, secrets and deployment identity are prerequisites. WordPress has separate entrypoints such as wp-login.php; this index.php-only configuration is not a drop-in WordPress configuration.<\/p>\n<p>Create a new <code>app<\/code> group and nonlogin <code>appweb<\/code>\/<code>appqueue<\/code> service identities as an administrator after checking for existing names. Keep deployed code unwritable by runtime identities; grant only required storage\/bootstrap\/cache access. appqueue needs the actual file\/database permissions of its jobs; its name does not automatically make it less privileged. The Nginx www-data identity needs parent traversal and read access to public files. Shared application secrets remain within the same application trust boundary.<\/p>\n<p>Create root-owned <code>\/etc\/php\/8.3\/fpm-app.d<\/code>, <code>\/var\/log\/php-fpm-app<\/code>, <code>\/etc\/supervisor-app-queue\/programs<\/code> and <code>\/var\/log\/app-queue<\/code>. Create <code>\/var\/lib\/app-sessions<\/code> with appweb ownership and mode 0700. Precreate each pool\u2019s .error.log as appweb:app, 0640, and define log rotation\/reopening and retention. Protect privileged service files, configuration and parent paths against developer\/runtime writes.<\/p>\n<p>The dedicated master below includes exactly the two application pools. Do not add a packaged www pool or unrelated pools to this include directory. Other running FPM masters\/pools still count against host capacity; this service does not stop them. Migrate the application\u2019s Nginx mapping with a maintenance\/rollback plan and avoid accidentally running duplicate capacity. Pools separate request-concurrency settings; they share one master\u2019s OPcache and are not full security boundaries.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[global]\npid = \/run\/php-fpm-app\/master.pid\nerror_log = \/var\/log\/php-fpm-app\/master.log\ndaemonize = no\ninclude = \/etc\/php\/8.3\/fpm-app.d\/*.conf\n<\/code><\/pre>\n<p>Save the master configuration at <code>\/etc\/php\/8.3\/fpm-app.conf<\/code> and this unit at <code>\/etc\/systemd\/system\/php-fpm-app.service<\/code>. The 4 GiB cap covers this master and both pools together; it does not reserve RAM separately for each pool. Hitting MemoryMax may terminate HTTP work too. These numbers are illustrative until workload-specific acceptance tests pass.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[Unit]\nDescription=Dedicated FPM master for the example application\nAfter=network.target\nStartLimitIntervalSec=60\nStartLimitBurst=5\n\n[Service]\nType=simple\nRuntimeDirectory=php-fpm-app\nRuntimeDirectoryMode=0755\nExecStart=\/usr\/sbin\/php-fpm8.3 --nodaemonize --fpm-config \/etc\/php\/8.3\/fpm-app.conf\nExecReload=\/bin\/kill -USR2 $MAINPID\nKillSignal=SIGQUIT\nKillMode=mixed\nTimeoutStopSec=75s\nRestart=on-failure\nRestartSec=5s\nMemoryHigh=3G\nMemoryMax=4G\nMemorySwapMax=0\nCPUAccounting=yes\nMemoryAccounting=yes\nIOAccounting=yes\n\n[Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n<p>Save the following as session_pool.conf and api_pool.conf in the dedicated include directory. 128 MiB PHP memory_limit is illustrative and not a total RSS ceiling.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[session_pool]\nuser = appweb\ngroup = app\nlisten = \/run\/php-fpm-app\/session_pool.sock\nlisten.owner = www-data\nlisten.group = www-data\nlisten.mode = 0660\npm = dynamic\npm.max_children = 12\npm.start_servers = 4\npm.min_spare_servers = 4\npm.max_spare_servers = 8\npm.max_requests = 1000\nrequest_terminate_timeout = 60s\nrequest_terminate_timeout_track_finished = yes\nrequest_slowlog_timeout = 5s\nslowlog = \/var\/log\/php-fpm-app\/session_pool.slow.log\ncatch_workers_output = yes\nclear_env = yes\nsecurity.limit_extensions = .php\nphp_admin_value[memory_limit] = 128M\nphp_admin_value[max_execution_time] = 30\nphp_admin_value[session.save_handler] = files\nphp_admin_value[session.save_path] = \/var\/lib\/app-sessions\nphp_admin_value[session.gc_maxlifetime] = 1440\nphp_admin_value[session.gc_probability] = 1\nphp_admin_value[session.gc_divisor] = 100\nphp_admin_value[session.auto_start] = 0\nphp_admin_value[session.use_strict_mode] = 1\nphp_admin_value[session.use_only_cookies] = 1\nphp_admin_value[session.cookie_httponly] = 1\nphp_admin_value[session.cookie_secure] = 1\nphp_admin_value[session.cookie_samesite] = Lax\nphp_admin_flag[display_errors] = off\nphp_admin_flag[log_errors] = on\nphp_admin_value[error_log] = \/var\/log\/php-fpm-app\/session_pool.error.log\n<\/code><\/pre>\n<p>The API pool has separate children and request ceilings, while retaining the same native session storage policy for this application if code explicitly uses sessions:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[api_pool]\nuser = appweb\ngroup = app\nlisten = \/run\/php-fpm-app\/api_pool.sock\nlisten.owner = www-data\nlisten.group = www-data\nlisten.mode = 0660\npm = dynamic\npm.max_children = 8\npm.start_servers = 2\npm.min_spare_servers = 2\npm.max_spare_servers = 4\npm.max_requests = 1000\nrequest_terminate_timeout = 15s\nrequest_terminate_timeout_track_finished = yes\nrequest_slowlog_timeout = 2s\nslowlog = \/var\/log\/php-fpm-app\/api_pool.slow.log\ncatch_workers_output = yes\nclear_env = yes\nsecurity.limit_extensions = .php\nphp_admin_value[memory_limit] = 128M\nphp_admin_value[max_execution_time] = 30\nphp_admin_value[session.save_handler] = files\nphp_admin_value[session.save_path] = \/var\/lib\/app-sessions\nphp_admin_value[session.gc_maxlifetime] = 1440\nphp_admin_value[session.gc_probability] = 1\nphp_admin_value[session.gc_divisor] = 100\nphp_admin_value[session.auto_start] = 0\nphp_admin_value[session.use_strict_mode] = 1\nphp_admin_value[session.use_only_cookies] = 1\nphp_admin_value[session.cookie_httponly] = 1\nphp_admin_value[session.cookie_secure] = 1\nphp_admin_value[session.cookie_samesite] = Lax\nphp_admin_flag[display_errors] = off\nphp_admin_flag[log_errors] = on\nphp_admin_value[error_log] = \/var\/log\/php-fpm-app\/api_pool.error.log\n<\/code><\/pre>\n<p>session.auto_start=0 does not prohibit application code from starting a session or make middleware stateless. Separate Redis databases for pools serving the same session would split state; keep the intended application\u2019s storage, expiration and cookie policy consistent.<\/p>\n<h3><span id=\"2_Route_requests_to_the_right_pool_via_Nginx\">2. Route requests to the right pool via Nginx<\/span><\/h3>\n<p>This complete site mapping is included inside Nginx\u2019s http context. <code>www.example.com<\/code> uses session_pool and <code>api.example.com<\/code> uses api_pool. An existing certificate\/key must cover both hostnames; Secure session cookies require HTTPS. Save the following parameter file as <code>\/etc\/nginx\/snippets\/front-controller-fastcgi.conf<\/code>. Do not also include a distribution-specific fastcgi_params file with potentially different script parameters.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">fastcgi_param QUERY_STRING $query_string;\nfastcgi_param REQUEST_METHOD $request_method;\nfastcgi_param CONTENT_TYPE $content_type;\nfastcgi_param CONTENT_LENGTH $content_length;\nfastcgi_param SCRIPT_FILENAME $document_root\/index.php;\nfastcgi_param SCRIPT_NAME \/index.php;\nfastcgi_param PATH_INFO &quot;&quot;;\nfastcgi_param REQUEST_URI $request_uri;\nfastcgi_param DOCUMENT_URI $document_uri;\nfastcgi_param DOCUMENT_ROOT $document_root;\nfastcgi_param SERVER_PROTOCOL $server_protocol;\nfastcgi_param REQUEST_SCHEME $scheme;\nfastcgi_param HTTPS $https if_not_empty;\nfastcgi_param GATEWAY_INTERFACE CGI\/1.1;\nfastcgi_param SERVER_SOFTWARE nginx\/$nginx_version;\nfastcgi_param REMOTE_ADDR $remote_addr;\nfastcgi_param REMOTE_PORT $remote_port;\nfastcgi_param SERVER_ADDR $server_addr;\nfastcgi_param SERVER_PORT $server_port;\nfastcgi_param SERVER_NAME $server_name;\nfastcgi_param HTTP_HOST $http_host;\nfastcgi_param HTTP_PROXY &quot;&quot;;\nfastcgi_param REDIRECT_STATUS 200;\n<\/code><\/pre>\n<pre class=\"language-nginx line-numbers\"><code class=\"language-nginx\">upstream php_session_pool {\n    server unix:\/run\/php-fpm-app\/session_pool.sock;\n}\nupstream php_api_pool {\n    server unix:\/run\/php-fpm-app\/api_pool.sock;\n}\n\nserver {\n    listen 443 ssl;\n    server_name www.example.com;\n    root \/var\/www\/site\/public;\n    index index.php;\n    ssl_certificate \/etc\/ssl\/app\/fullchain.pem;\n    ssl_certificate_key \/etc\/ssl\/app\/privkey.pem;\n    access_log \/var\/log\/nginx\/www.example.com.access.log;\n    error_log \/var\/log\/nginx\/www.example.com.error.log;\n    client_max_body_size 10m;\n\n    location = \/index.php {\n        try_files \/index.php =404;\n        include \/etc\/nginx\/snippets\/front-controller-fastcgi.conf;\n        fastcgi_pass php_session_pool;\n        fastcgi_connect_timeout 3s;\n        fastcgi_read_timeout 65s;\n    }\n    location ~ \/\\. { return 404; }\n    location ~* \\.php(?:\/|$) { return 404; }\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$query_string;\n    }\n}\n\nserver {\n    listen 443 ssl;\n    server_name api.example.com;\n    root \/var\/www\/site\/public;\n    index index.php;\n    ssl_certificate \/etc\/ssl\/app\/fullchain.pem;\n    ssl_certificate_key \/etc\/ssl\/app\/privkey.pem;\n    access_log \/var\/log\/nginx\/api.example.com.access.log;\n    error_log \/var\/log\/nginx\/api.example.com.error.log;\n    client_max_body_size 10m;\n\n    location = \/index.php {\n        try_files \/index.php =404;\n        include \/etc\/nginx\/snippets\/front-controller-fastcgi.conf;\n        fastcgi_pass php_api_pool;\n        fastcgi_connect_timeout 3s;\n        fastcgi_read_timeout 20s;\n    }\n    location ~ \/\\. { return 404; }\n    location ~* \\.php(?:\/|$) { return 404; }\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$query_string;\n    }\n}\n<\/code><\/pre>\n<p>Only an existing <code>public\/index.php<\/code> is executed. Other .php paths, \/index.php\/extra PATH_INFO requests and dot paths are rejected; uploaded PHP files are not executable entrypoints. REQUEST_URI, query and POST parameters are preserved. Applications with multiple real entry files need their own routing contract. fastcgi_read_timeout measures the interval between successive reads, not an absolute request duration.<\/p>\n<p>For same-host API routing, add these two locations only inside the www server block. <code>\/api<\/code> and <code>\/api\/...<\/code> use the API pool; <code>\/apix<\/code> retains the normal pool. The \/api\/ prefix deliberately omits ^~ so the existing PHP\/dot-path denial regexes still apply. SCRIPT_FILENAME remains fixed to index.php; the application receives its original REQUEST_URI.<\/p>\n<pre class=\"language-nginx line-numbers\"><code class=\"language-nginx\">location = \/api {\n    try_files \/index.php =404;\n    include \/etc\/nginx\/snippets\/front-controller-fastcgi.conf;\n    fastcgi_pass php_api_pool;\n    fastcgi_connect_timeout 3s;\n    fastcgi_read_timeout 20s;\n}\nlocation \/api\/ {\n    try_files \/index.php =404;\n    include \/etc\/nginx\/snippets\/front-controller-fastcgi.conf;\n    fastcgi_pass php_api_pool;\n    fastcgi_connect_timeout 3s;\n    fastcgi_read_timeout 20s;\n}\n<\/code><\/pre>\n<p>The single-front-controller contract fits an application that really dispatches through public\/index.php. A WordPress login endpoint must execute its actual entrypoint, not be mislabeled as index.php. Test allowed routes, missing entry files, upload\/PATH_INFO rejection and query\/POST preservation before deployment.<\/p>\n<h3><span id=\"3_Configure_queue_workers_with_Supervisor\">3. Configure queue workers with Supervisor<\/span><\/h3>\n<p>Choose one of the two managers below; never start the same worker set under both Supervisor and direct systemd. Prerequisites are a working Laravel application, required CLI extensions including PCNTL for timeouts, an existing database queue connection\/tables and a least-privileged worker identity. Set <code>retry_after=90<\/code> on the actual database connection in <code>config\/queue.php<\/code>; the queue is default. Job-level overrides must not exceed 60 s. Adapt the relationship 60 s worker timeout &lt;75 s graceful stop &lt;90 s retry_after to real jobs and I\/O. SQS uses visibility timeout instead of retry_after.<\/p>\n<p>CLI does not inherit pool-specific INI settings: inspect <code>php8.3 --ini<\/code> and extensions in the CLI context. PHP memory_limit limits managed allocations, not total RSS; as of PHP 8.3.36 and related updated branches it is a soft allocation limit that may briefly be exceeded. Laravel &#8211;memory is a worker recycling threshold, while cgroup MemoryMax is an aggregate OS boundary. They are different mechanisms. Configure application\/external-I\/O timeouts, idempotent effects and retry\/failure handling as well.<\/p>\n<p>Do not start a second Supervisor using the existing global \/etc\/supervisor\/supervisord.conf. Use <code>\/etc\/supervisor-app-queue\/supervisord.conf<\/code>, including only this application\u2019s program directory. It has its own Unix control socket and PID file, without a TCP control interface.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[unix_http_server]\nfile=\/run\/app-queue-supervisor\/control.sock\nchmod=0700\n\n[supervisord]\nnodaemon=true\npidfile=\/run\/app-queue-supervisor\/supervisord.pid\nlogfile=\/var\/log\/app-queue\/supervisord.log\nlogfile_maxbytes=10MB\nlogfile_backups=3\nchildlogdir=\/var\/log\/app-queue\n\n[rpcinterface:supervisor]\nsupervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface\n\n[supervisorctl]\nserverurl=unix:\/\/\/run\/app-queue-supervisor\/control.sock\n\n[include]\nfiles=\/etc\/supervisor-app-queue\/programs\/*.conf\n<\/code><\/pre>\n<p>Save this program as <code>\/etc\/supervisor-app-queue\/programs\/queue.conf<\/code>. The command is a single line. Each of the four processes has a distinct rotating log file; sharing one rotating file can corrupt logs.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[program:app-queue]\nprocess_name=%(program_name)s_%(process_num)02d\ncommand=\/usr\/bin\/php8.3 -d memory_limit=384M \/var\/www\/site\/artisan queue:work database --queue=default --sleep=1 --tries=3 --timeout=60 --memory=256 --max-time=3600\ndirectory=\/var\/www\/site\nnumprocs=4\nuser=appqueue\nautostart=true\nautorestart=true\nstartsecs=1\nstartretries=3\nstopsignal=TERM\nstopwaitsecs=75\nstopasgroup=true\nkillasgroup=true\nredirect_stderr=true\nstdout_logfile=\/var\/log\/app-queue\/worker_%(process_num)02d.log\nstdout_logfile_maxbytes=10MB\nstdout_logfile_backups=3\n<\/code><\/pre>\n<p>Install the dedicated parent unit at \/etc\/systemd\/system\/app-queue-supervisor.service:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[Unit]\nDescription=Dedicated Supervisor for application queue workers\nAfter=network.target\nStartLimitIntervalSec=60\nStartLimitBurst=5\n\n[Service]\nType=simple\nRuntimeDirectory=app-queue-supervisor\nRuntimeDirectoryMode=0700\nExecStart=\/usr\/bin\/supervisord -n -c \/etc\/supervisor-app-queue\/supervisord.conf\nRestart=on-failure\nRestartSec=5s\nKillMode=mixed\nTimeoutStopSec=90s\nCPUAccounting=yes\nCPUQuota=150%\nMemoryAccounting=yes\nMemoryHigh=1536M\nMemoryMax=2G\nMemorySwapMax=0\nIOAccounting=yes\nIOWeight=50\n\n[Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n<p>Key points:<\/p>\n<p>All four CLI workers and their Supervisor share this cgroup budget. CPUQuota=150% is 1.5 CPUs worth of CPU time, approximately 37.5% of a 4 vCPU host; it does not reserve CPU for FPM. Use a single percent sign. MemoryHigh=1536M throttles under pressure; MemoryMax=2G may cause an in-cgroup OOM as a last defense, without guaranteeing the whole host cannot run out of memory. Swap is separately capped at 0. IOWeight=50 is relative to the default 100; a higher weight would favor the queue. Effect depends on the active controller, scheduler and hierarchy.<\/p>\n<p>KillMode=mixed initially signals the Supervisor main process. Supervisor signals its worker groups and waits 75 s; the outer 90 s stop window allows additional shutdown time before remaining processes may be killed. Completion and exactly-once effects are not guaranteed. Repeated startup failures can hit StartLimit; investigate instead of assuming retries continue forever.<\/p>\n<h3><span id=\"4_Or_run_workers_via_systemd_units\">4. Or run workers via systemd units<\/span><\/h3>\n<p>Alternatively, omit Supervisor and install the shared <code>\/etc\/systemd\/system\/app-queue.slice<\/code> plus <code>\/etc\/systemd\/system\/app-queue&#64;.service<\/code> below. Every instance belongs to the same aggregate 2 GiB\/150% budget; a 512 MiB per-instance ceiling does not create a separate 2 GiB allowance per worker. The instance number identifies a process, not a queue: all four explicitly consume default.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[Unit]\nDescription=Aggregate resource budget for application queue workers\n\n[Slice]\nCPUAccounting=yes\nCPUQuota=150%\nMemoryAccounting=yes\nMemoryHigh=1536M\nMemoryMax=2G\nMemorySwapMax=0\nIOAccounting=yes\nIOWeight=50\n<\/code><\/pre>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">[Unit]\nDescription=Application queue worker instance %i\nAfter=network.target\nStartLimitIntervalSec=60\nStartLimitBurst=5\n\n[Service]\nType=simple\nUser=appqueue\nGroup=app\nWorkingDirectory=\/var\/www\/site\nExecStart=\/usr\/bin\/php8.3 -d memory_limit=384M \/var\/www\/site\/artisan queue:work database --queue=default --sleep=1 --tries=3 --timeout=60 --memory=256 --max-time=3600\nRestart=always\nRestartSec=5s\nSuccessExitStatus=0\nKillSignal=SIGTERM\nKillMode=mixed\nTimeoutStopSec=75s\nSlice=app-queue.slice\nMemoryMax=512M\nStandardOutput=journal\nStandardError=journal\n\n[Install]\nWantedBy=multi-user.target\n<\/code><\/pre>\n<p>Restart=always also restarts normal exits from &#8211;max-time or queue:restart; an intentional systemctl stop does not automatically restart the service. The same CLI\/PCNTL, job-timeout and graceful-stop prerequisites apply. Verify the actual slice hierarchy and enabled controllers.<\/p>\n<p>After staged syntax and application acceptance checks, an administrator may start only the selected manager. These commands operate real services; establish a maintenance\/rollback plan and stop duplicate worker ownership first:<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">systemd-analyze verify \/etc\/systemd\/system\/app-queue&#64;.service \/etc\/systemd\/system\/app-queue.slice\nsystemctl daemon-reload\nsystemctl enable --now app-queue&#64;1 app-queue&#64;2 app-queue&#64;3 app-queue&#64;4\n<\/code><\/pre>\n<p>The shared slice limits the sum of workers, and each worker has a 512 MiB cap. It does not reserve the remaining host resources for FPM or prove the desired latency. If Supervisor is selected instead, start app-queue-supervisor.service and inspect it with supervisorctl using the dedicated configuration path.<\/p>\n<h3><span id=\"5_Observability_separate_logs_and_metrics\">5. Observability: separate logs and metrics<\/span><\/h3>\n<p>Measure each pool and worker layer so you can connect symptoms to the workload that produced them:<\/p>\n<ul>\n<li>Separate Nginx access\/error and FPM slow\/error logs, with protected rotation\/retention.<\/li>\n<li>FPM active\/idle children, listen queue, max children reached and slow requests; keep status access private.<\/li>\n<li>Queue age\/backlog, job duration\/retries\/failures and worker exits.<\/li>\n<li>CPU throttling, cgroup memory.events\/MemoryCurrent, PSS\/USS\/RSS and storage\/database pressure. RSS is KiB and may count shared pages repeatedly.<\/li>\n<\/ul>\n<p>If you are not yet monitoring your VPS in a structured way, our guide on <a href=\"https:\/\/www.dchost.com\/blog\/en\/vps-monitoring-prometheus-grafana-uptime-kuma\/\">VPS monitoring and alerts with Prometheus, Grafana and Uptime Kuma<\/a> is a good starting point.<\/p>\n<pre class=\"language-bash line-numbers\"><code class=\"language-bash\">ps -eo pid,user,rss,args --sort=-rss | awk &#039;\/php-fpm: pool\/ &amp;&amp; !\/awk\/ {print}&#039;\nsystemctl show php-fpm-app.service -p MemoryCurrent -p MemoryHigh -p MemoryMax -p ControlGroup\nsystemctl show app-queue-supervisor.service -p CPUQuotaPerSecUSec -p MemoryCurrent -p MemoryMax -p ControlGroup\n<\/code><\/pre>\n<p>For direct systemd workers inspect app-queue.slice and the selected instance units instead of the Supervisor unit. A short process listing or an idle average is not a peak-capacity measurement.<\/p>\n<h2><span id=\"Relating_This_to_PerSite_PHPFPM_Pool_Architecture\">Relating This to Per\u2011Site PHP\u2011FPM Pool Architecture<\/span><\/h2>\n<h3><span id=\"Persite_and_perrole_pools_together\">Per\u2011site and per\u2011role pools together<\/span><\/h3>\n<p>In many agency or multi\u2011project setups, you already run <strong>one FPM pool per site<\/strong> (or per customer). In that model, you can still apply the same idea, just one level deeper:<\/p>\n<ul>\n<li>Each site may have its own HTTP session\/API pools and independent CLI queue services.<\/li>\n<li>Count all pools\/masters\/workers and dependencies in the host budget.<\/li>\n<li>Unrelated applications need distinct identities, file\/secret\/session policies and stronger boundaries where the trust model requires them.<\/li>\n<\/ul>\n<p>The <a href=\"https:\/\/www.dchost.com\/blog\/en\/one-server-many-phps-how-i-run-per-site-nginx-php-fpm-pools-without-the-drama\/\">per-site Nginx\/PHP-FPM guide<\/a> gives related context. A per-site or per-role pool name is not complete tenant isolation; same-master OPcache and shared host resources remain.<\/p>\n<h3><span id=\"When_to_move_beyond_a_single_server\">When to move beyond a single server<\/span><\/h3>\n<p>At some point, even a well\u2011designed pool architecture on one VPS will hit its limits: queue workloads grow, databases need more IOPS, or uptime requirements push you to redundancy. That\u2019s when it starts to make sense to:<\/p>\n<ul>\n<li>Move queue, Redis or database roles to an appropriate separate <a href=\"https:\/\/www.dchost.com\/dedicated-server\">dedicated server<\/a> or VPS where the measured trust\/capacity requirement justifies it.<\/li>\n<li>Load balancing needs consistent session\/application data and health\/rollout controls.<\/li>\n<li>GeoDNS\/multi-region routing additionally needs data replication, failover and recovery design; DNS alone does not provide redundancy.<\/li>\n<\/ul>\n<p>We\u2019ve covered bigger\u2011picture hosting decisions for PHP apps in articles like <a href=\"https:\/\/www.dchost.com\/blog\/en\/choosing-hosting-for-laravel-symfony-and-custom-php-apps\/\">choosing hosting for Laravel, Symfony and custom PHP apps<\/a> and our guide to <a href=\"https:\/\/www.dchost.com\/blog\/en\/geodns-and-multi-region-hosting-architecture\/\">GeoDNS and multi\u2011region hosting architecture<\/a>.<\/p>\n<h2><span id=\"Operational_Tips_and_Common_Pitfalls\">Operational Tips and Common Pitfalls<\/span><\/h2>\n<h3><span id=\"Avoiding_deadlocks_and_session_contention\">Avoiding deadlocks and session contention<\/span><\/h3>\n<p>Isolating pools does not magically fix all session issues. Watch out for:<\/p>\n<ul>\n<li>A native-session request holding its handler lock during slow I\/O.<\/li>\n<li>Framework\/session handlers with their own concurrent-update or blocking semantics.<\/li>\n<li>Different stores\/expiry\/cookies across pools serving the same application, or improperly shared stores across unrelated applications.<\/li>\n<\/ul>\n<p>FPM status can show busy processes or a backlog; it does not directly label a session-lock wait. Correlate slow traces, handler behavior, application timing and concurrent requests before diagnosing:<\/p>\n<ul>\n<li>Reduce unnecessary work while the native session is open; after session_write_close later changes are not automatically saved.<\/li>\n<li>Keep large work products outside session data and preserve application-level consistency.<\/li>\n<li>Choose and test storage handler locking\/TTL behavior explicitly; Redis or Memcached alone does not remove contention.<\/li>\n<\/ul>\n<h3><span id=\"Graceful_deploys_with_queue_and_pool_isolation\">Graceful deploys with queue and pool isolation<\/span><\/h3>\n<p>Manage deployment as a coordinated process change with retained state and rollback:<\/p>\n<ul>\n<li>Drain\/stop the selected queue manager with a grace window longer than the maximum intended job; forced termination can still occur.<\/li>\n<li>FPM reload targets the master\/service and its pools; a generic php-fpm reload command does not gradually reload individual pools. Validate the selected config and service\u2019s actual reload behavior.<\/li>\n<li>For <a href=\"https:\/\/www.dchost.com\/blog\/en\/zero-downtime-deployments-to-a-vps-with-github-actions-for-php-and-node-js\/\">symlink release deployments<\/a>, coordinate worker restarts, OPcache\/realpath behavior, backward-compatible data changes and persistent session storage; separate pools do not guarantee zero downtime.<\/li>\n<\/ul>\n<p>For more complex Laravel setups, our detailed guide on <a href=\"https:\/\/www.dchost.com\/blog\/en\/laravel-vps-deployment-nginx-php-fpm-horizon\/\">deploying Laravel on a VPS with Nginx, PHP\u2011FPM, Horizon and zero\u2011downtime releases<\/a> shows exactly how these pieces fit together.<\/p>\n<p>Laravel queue:restart signals are stored through the application cache; workers need the correct shared cache configuration and manager restart policy. Test current-job completion, retry behavior and rollback with sandbox effects before relying on graceful restarts.<\/p>\n<h3><span id=\"Testing_before_enabling_in_production\">Testing before enabling in production<\/span><\/h3>\n<p>When you introduce new pools and worker processes, always test on staging first:<\/p>\n<ul>\n<li>Use a staging copy with separate credentials\/data and blocked email\/payment\/webhook effects.<\/li>\n<li>Test both hostname and optional prefix routing, existing\/missing index.php, denied PHP\/PATH_INFO\/dot paths and query\/POST preservation.<\/li>\n<li>Verify real application login\/cart\/checkout state and concurrent updates; native PHP session fixtures do not prove framework behavior.<\/li>\n<li>Apply mixed HTTP\/queue load while recording p95\/p99\/errors, FPM backlog, queue age, throttling and memory pressure.<\/li>\n<li>Exercise manager stop\/restart, timed-out\/retried jobs, rollback and actual cgroup limits; syntax acceptance does not prove these.<\/li>\n<\/ul>\n<p>We\u2019ve written a practical guide on <a href=\"https:\/\/www.dchost.com\/blog\/en\/load-test-hosting-with-k6-jmeter-and-locust\/\">load testing your hosting before traffic spikes<\/a> that pairs nicely with this kind of architecture change.<\/p>\n<h2><span id=\"Keep_HTTP_Capacity_and_CLI_Worker_Budgets_Explicit\">Keep HTTP Capacity and CLI Worker Budgets Explicit<\/span><\/h2>\n<p>Use FPM pools for distinct HTTP concurrency\/timeouts and separate managed CLI processes for queue work. Shared native-session state follows the application boundary; resource controls follow the actual service\/cgroup hierarchy. Neither a pool name nor a successful config parse proves isolation or production capacity.<\/p>\n<p>Begin with measured budgets, explicit worker ownership and protected configuration. Validate routing, state consistency, retries and graceful\/forced stopping before rollout. Keep observability and recovery steps with the configuration as the workload changes.<\/p>\n<p>For a new PHP deployment or a refactor, document the application\u2019s workloads, entrypoints, session handler and operational responsibilities before choosing capacity. Adapt the examples in a separate test environment and verify the management responsibilities included in the hosting service. This design provides controls to test and operate; it does not promise faster responses, zero downtime or complete tenant isolation.<\/p>\n<h2><span id=\"Technical_References\">Technical References<\/span><\/h2>\n<ul>\n<li><a href=\"https:\/\/www.php.net\/manual\/en\/install.fpm.configuration.php\" rel=\"nofollow noopener\" target=\"_blank\">PHP-FPM<\/a><\/li>\n<li><a href=\"https:\/\/www.php.net\/manual\/en\/function.session-write-close.php\" rel=\"nofollow noopener\" target=\"_blank\">session_write_close<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/phpredis\/phpredis\/blob\/6.2.0\/README.md#php-session-handler\" rel=\"nofollow noopener\" target=\"_blank\">PhpRedis 6.2.0<\/a><\/li>\n<li><a href=\"https:\/\/laravel.com\/docs\/13.x\/queues\" rel=\"nofollow noopener\" target=\"_blank\">Laravel queues<\/a><\/li>\n<li><a href=\"https:\/\/supervisord.org\/configuration.html\" rel=\"nofollow noopener\" target=\"_blank\">Supervisor<\/a><\/li>\n<li><a href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/255\/systemd.resource-control.html\" rel=\"nofollow noopener\" target=\"_blank\">systemd resource control<\/a><\/li>\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_core_module.html#location\" rel=\"nofollow noopener\" target=\"_blank\">Nginx location<\/a><\/li>\n<\/ul>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Separate PHP-FPM HTTP pools from CLI queue workers, preserve session state, and validate Nginx routing, worker lifecycle and aggregate CPU\/memory budgets.<\/p>\n","protected":false},"author":1,"featured_media":13137,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[184],"tags":[],"class_list":["post-3710","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts\/3710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/comments?post=3710"}],"version-history":[{"count":7,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts\/3710\/revisions"}],"predecessor-version":[{"id":13139,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/posts\/3710\/revisions\/13139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/media\/13137"}],"wp:attachment":[{"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/media?parent=3710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/categories?post=3710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dchost.com\/blog\/en\/wp-json\/wp\/v2\/tags?post=3710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}