Skip to content

GraphQL App Server

Module: Magenx_AppServer · no admin settings, no GraphQL changes

PHP-FPM rebuilds the whole of Magento for every GraphQL request, and on the cheap catalog reads a headless storefront makes constantly, that start-up is most of the time. This module serves /graphql from FrankenPHP workers that boot Magento once, keep it in memory, and reset it after every request. Answers come faster and cost less, and PHP-FPM stays in place as the fallback.

It is an open-source take on the idea behind Adobe Commerce’s application server; no Adobe code is used.

In the first tests on a live storefront, the median GraphQL response time dropped by 47%, from 182 ms to 97 ms. See Performance.

traffic sharerest503 + marker:out of scope, maintenanceworker down

nginx /graphql

FrankenPHP worker
(Magento booted once)

PHP-FPM

For each request the worker:

  1. refills its request object from the new request and drops cookies (GraphQL uses tokens, never PHP sessions);
  2. checks the request is within its mode and that maintenance is off; otherwise it answers 503 with a marker header, before Magento runs, and nginx replays the request on PHP-FPM;
  3. runs Magento’s normal GraphQL pipeline and sends the response;
  4. after sending, rolls back any open transaction, ends any started session, and resets every object it built.

nginx replays a request on PHP-FPM only when the worker can’t have run it: the worker refused it with its marker, never received it, or it is a GET. A POST the worker received and then failed on is not replayed; the client gets the error. Otherwise a retried mutation could, for example, place an order twice.

A worker exits cleanly, and FrankenPHP starts a fresh one, after any of these:

  • an uncaught error, or a transaction left open;
  • 500 requests (MAGENX_WORKER_MAX_REQUESTS), 512 MB of memory (MAGENX_WORKER_MAX_MEMORY_MB) or 30 minutes (MAGENX_WORKER_MAX_AGE);
  • a change to app/etc/env.php;
  • a configuration cache rebuild: saving settings in the admin, cache:clean config or cache:flush.

Limits have ±20% jitter, so workers that started together don’t all restart together. Every boot and exit is logged in var/log/system.log with its reason:

Terminal window
grep 'magenx-app-server: worker' var/log/system.log | grep -oE 'booted|recycling \([^)]*\)|stopped by FrankenPHP' | sort | uniq -c

MAGENX_WORKER_MODE on the worker container decides what workers serve:

ModeServed by the workerSent to PHP-FPM
restricted (default)Anonymous, read-only queries on the allow list: catalog, categories, CMS, store config, URL resolution, and the companion modules’ public queries (best sellers, blog, deals, GARAN notice, cookie groups, quick search, store locations).Customer tokens, mutations, anything off the allow list.
defaultEvery /graphql request: customers, carts, checkout and all mutations.Large request bodies, maintenance, worker unreachable.

Change the allow list with MAGENX_WORKER_ALLOWED_FIELDS (comma-separated). Add a field only after checking its resolvers keep no per-customer data. Bodies over MAGENX_WORKER_MAX_BODY_KB (default 512) are always sent to PHP-FPM.

Switch modes by setting the variable in .env and recreating the container (docker compose up -d; restart keeps the old environment). Each worker logs its mode when it boots.

  1. Install the module and start the worker container in restricted mode.
  2. Send a share of /graphql traffic to the workers, for example 10%, through nginx.
  3. Watch the boot and restart log lines and the latency; raise the share.
  4. Before switching to default mode, run the verification gate: the cross-request state tests with every installed module enabled, a shadow comparison of real queries against both backends, and a load test.

To compare backends, add $upstream_addr and $graphql_backend to the graphql_timing nginx log format. It also shows how often requests are replayed.

Workers hold configuration in memory. After a deploy (setup:upgrade, setup:di:compile, new code), restart the worker container so it boots from the new release; nginx serves /graphql from PHP-FPM meanwhile. Admin configuration saves need nothing: workers restart on the configuration cache rebuild.

Every GraphQL operation of the companion modules has a cross-request state test. It runs the operation for customer A, then customer B, and fails when B’s answer contains A’s data or a shared object changed. A coverage test fails when a new operation has no such test.

First measurements, October 2026: PHP-FPM only against the FrankenPHP worker in restricted mode, on the same server, catalog and storefront.

SetupRequestsWhat serves /graphql
PHP-FPM only (baseline)675nginx sends every request to PHP-FPM. Magento boots from scratch on each request.
FrankenPHP worker485Anonymous read-only queries go to the workers. Everything else falls back to PHP-FPM.

How it was measured:

  • Real page browsing on the storefront, not a synthetic load test.
  • Timer: the Next.js storefront’s GraphQL profiler, so each time includes the network and the nginx hop.
  • Three rounds per backend, merged. Every logged request counted.
  • Cart and helpdesk calls run on PHP-FPM in both setups. They are kept apart as a control group.
  • Server: a small 2 vCPU Hetzner Cloud machine, with Magento cron running.

For the queries the worker serves (649 PHP-FPM and 456 FrankenPHP requests):

MeasurePHP-FPMFrankenPHPChange
Median182 ms97 ms−47%
Mean without outliers238 ms147 ms−38%
90th percentile402 ms267 ms−34%
Mean of all requests251 ms156 ms−38%

“Without outliers” leaves out requests of 800 ms or more: 9 on PHP-FPM, 2 on FrankenPHP. The mean of all requests includes a few one-off spikes of up to 3.8 s.

More requests finish quickly:

Requests faster thanPHP-FPMFrankenPHP
100 ms1%51%
200 ms54%70%
300 ms67%93%

A product page runs three worker queries: detail, reviews and blog posts. Their medians add up to 651 ms on PHP-FPM and 342 ms on FrankenPHP (−47%). This is server work, not page load time: the storefront may run the three in parallel.

Median per query, for the 10 queries with at least 10 PHP-FPM samples. Samples are PHP-FPM / FrankenPHP.

QuerySamplesPHP-FPMFrankenPHPChange
GetBlogPostsByProduct168 / 116127 ms59 ms−53%
GetProductDetail162 / 114362 ms210 ms−42%
GetProductReviews149 / 103162 ms74 ms−55%
GetProductLinkedProducts26 / 24496 ms314 ms−37%
GetCmsBlocks25 / 16175 ms140 ms−20%
GetProductsByCategory23 / 19294 ms214 ms−27%
GetCategoryAggregations15 / 9219 ms112 ms−49%
GetCategoryByUrlKey13 / 6166 ms75 ms−55%
GetBestSellers11 / 4242 ms109 ms−55%
GetNavigationCategories10 / 7278 ms248 ms−11%

Results with fewer than 10 samples on one side show the direction only.

95% confidence intervals of the median, from a bootstrap with 10,000 resamples of the measured requests:

QueryPHP-FPM medianFrankenPHP medianChange
All worker queries176–199 ms86–114 ms−37 to −55%
GetProductDetail354–373 ms204–217 ms−40 to −44%
GetBlogPostsByProduct124–130 ms57–62 ms−51 to −55%
GetProductReviews157–168 ms70–76 ms−52 to −57%
GetProductsByCategory279–317 ms198–227 ms−21 to −35%

The ranges do not overlap. Even the slowest likely FrankenPHP median beats the fastest likely PHP-FPM median, overall and for each frequent query.

Cart, mutation and helpdesk calls are outside restricted mode, so they ran on PHP-FPM in both setups (26 calls in the PHP-FPM run, 29 in the worker run):

QueryPHP-FPM runWorker run
AddProductsToCart499 ms505 ms
GetCartDetails318 ms323 ms
GetCartCrossSells317 ms347 ms
RemoveItemFromCart254 ms298 ms
All 55 control calls325 ms345 ms

The control median changed by +6%, with a 95% range of −10% to +16%: within noise. Server and load were the same in both setups, so the gain on worker queries comes from the worker, not from a quieter test run.

  • Removed: about 60–100 ms per request. PHP-FPM rebuilds Magento for every request: bootstrap, area and DI configuration, the object graph, and configuration reads from Valkey. The worker does this once at boot and keeps it in memory.
  • Unchanged: the query’s own work. MySQL, OpenSearch and resolver logic cost the same on both. So light queries take about half the time, and heavy ones, such as category listings and linked products, drop by 25–40%.

The tail is better, but rare spikes remain on both backends:

PHP-FPMFrankenPHP
p95495 ms330 ms
p99947 ms605 ms
max1720 ms3826 ms

The likely cause is the small test server, which also runs Magento cron. This was live browsing, not a controlled benchmark. Next steps:

  1. Replay the same query list on both backends, alternating, and compare p50 and p95.
  2. Match each spike to cron runs and to worker boot or recycle lines in the log.
  3. Size GRAPHQL_WORKERS to peak bursts, so that extra threads rarely need to boot.
  4. Keep cart and customer queries on PHP-FPM until they are tested for state safety, then consider default mode.
  • FrankenPHP with thread-safe (ZTS) PHP 8.4 or later. The official dunglas/frankenphp images qualify.
  • Production mode: compiled DI (setup:di:compile) is required; workers refuse to start without it.
  • The worker container uses the same code and app/etc/env.php as PHP-FPM. The module ships the worker image, Caddyfile, compose override and nginx templates for the magenx Docker stack.

Limits:

  • Plugins on Magento’s HTTP application class don’t run. In core that is only New Relic reporting, which doesn’t support thread-safe PHP anyway.
  • A module calling exit() or die() ends the worker thread mid-request.
  • File uploads (multipart) aren’t supported. Core GraphQL has none.
  • One request per thread. Never enable coroutine-style concurrency.

These always hold:

  • A response never contains data from another request.
  • No request is executed twice: only requests the worker did not run (marked refusal, never received, or GET) are replayed.
  • For the same request the worker's response equals the classic server's.
  • Without workers, the site behaves exactly as before.
  • Restricted mode never runs credentials, writes, carts or checkout.
  • Effective request / age limit = configured × (1 ± random up to 20%) per worker.
  • Replay when: nothing reached the worker, OR the marker is present, OR the method is GET.
  • A settings change reaches every worker within about one second of the cache rebuild.
  • Upgrading never widens what an existing install sends to workers.
SituationWhat happens
Request carries a session cookie.Cookie dropped.
Code leaves a transaction open.Rolled back; worker recycles.
Worker container stopped.Classic server serves everything; web server still starts.
Worker times out on a write it received.Error returned; no replay.
Body larger than the maximum.Refused before parsing; replayed.
All caches flushed.Workers recycle on their next request.
Unknown mode value.Worker does not start.
  • Production deployments with pre-compiled configuration.
  • Full mode only after the verification gate passes with every installed feature.
  • Serving the admin, REST or server-rendered pages.
  • Development mode (pre-compiled application configuration is required).
  • Serving customer, cart or checkout traffic while any installed feature keeps per-customer state that cannot be reset.
  • Replacing the classic server.
Terminal window
composer require magenxcommerce/module-graph-ql-app-server
bin/magento module:enable Magenx_AppServer
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
  • PHP ~8.4.0||~8.5.0, Magento 2.4.8.

Enabling the module changes nothing for PHP-FPM: it adds no plugins or observers. Only the workers use it.

TermMeaning
WorkerA long-lived process that starts the application once and serves many requests.
Request stateData belonging to one request (customer, cart, store, parsed query).
ResetReturning every tracked object to its freshly built state after a request.
Reset declarationA list of object properties and their reset values for code that cannot reset itself.
Restricted modeWorker serves only anonymous, read-only, allow-listed operations.
Full modeWorker serves every API request.
Out of scopeA request the current mode does not serve; refused with a marker.
ReplayThe web server re-sending a request to the classic server.
RecycleWorker exits cleanly and a fresh one starts.
Traffic sharePercentage of API traffic sent to workers first.
State testRuns each operation twice in one application and fails when any shared object changed.