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.
How it works
Section titled “How it works”For each request the worker:
- refills its request object from the new request and drops cookies (GraphQL uses tokens, never PHP sessions);
- 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;
- runs Magento’s normal GraphQL pipeline and sends the response;
- after sending, rolls back any open transaction, ends any started session, and resets every object it built.
Fallback never runs a request twice
Section titled “Fallback never runs a request twice”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.
Workers restart before problems build up
Section titled “Workers restart before problems build up”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 configorcache: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:
grep 'magenx-app-server: worker' var/log/system.log | grep -oE 'booted|recycling \([^)]*\)|stopped by FrankenPHP' | sort | uniq -cMAGENX_WORKER_MODE on the worker container decides what workers serve:
| Mode | Served by the worker | Sent 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. |
default | Every /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.
Roll out
Section titled “Roll out”- Install the module and start the worker container in
restrictedmode. - Send a share of
/graphqltraffic to the workers, for example 10%, through nginx. - Watch the boot and restart log lines and the latency; raise the share.
- Before switching to
defaultmode, 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.
Deploys
Section titled “Deploys”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.
For module developers
Section titled “For module developers”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.
Performance
Section titled “Performance”First measurements, October 2026: PHP-FPM only against the FrankenPHP worker in restricted mode, on the same server, catalog and storefront.
| Setup | Requests | What serves /graphql |
|---|---|---|
| PHP-FPM only (baseline) | 675 | nginx sends every request to PHP-FPM. Magento boots from scratch on each request. |
| FrankenPHP worker | 485 | Anonymous 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.
Typical request: 47% faster
Section titled “Typical request: 47% faster”For the queries the worker serves (649 PHP-FPM and 456 FrankenPHP requests):
| Measure | PHP-FPM | FrankenPHP | Change |
|---|---|---|---|
| Median | 182 ms | 97 ms | −47% |
| Mean without outliers | 238 ms | 147 ms | −38% |
| 90th percentile | 402 ms | 267 ms | −34% |
| Mean of all requests | 251 ms | 156 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 than | PHP-FPM | FrankenPHP |
|---|---|---|
| 100 ms | 1% | 51% |
| 200 ms | 54% | 70% |
| 300 ms | 67% | 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.
Every frequent query got faster
Section titled “Every frequent query got faster”Median per query, for the 10 queries with at least 10 PHP-FPM samples. Samples are PHP-FPM / FrankenPHP.
| Query | Samples | PHP-FPM | FrankenPHP | Change |
|---|---|---|---|---|
GetBlogPostsByProduct | 168 / 116 | 127 ms | 59 ms | −53% |
GetProductDetail | 162 / 114 | 362 ms | 210 ms | −42% |
GetProductReviews | 149 / 103 | 162 ms | 74 ms | −55% |
GetProductLinkedProducts | 26 / 24 | 496 ms | 314 ms | −37% |
GetCmsBlocks | 25 / 16 | 175 ms | 140 ms | −20% |
GetProductsByCategory | 23 / 19 | 294 ms | 214 ms | −27% |
GetCategoryAggregations | 15 / 9 | 219 ms | 112 ms | −49% |
GetCategoryByUrlKey | 13 / 6 | 166 ms | 75 ms | −55% |
GetBestSellers | 11 / 4 | 242 ms | 109 ms | −55% |
GetNavigationCategories | 10 / 7 | 278 ms | 248 ms | −11% |
Results with fewer than 10 samples on one side show the direction only.
The gain is not luck
Section titled “The gain is not luck”95% confidence intervals of the median, from a bootstrap with 10,000 resamples of the measured requests:
| Query | PHP-FPM median | FrankenPHP median | Change |
|---|---|---|---|
| All worker queries | 176–199 ms | 86–114 ms | −37 to −55% |
GetProductDetail | 354–373 ms | 204–217 ms | −40 to −44% |
GetBlogPostsByProduct | 124–130 ms | 57–62 ms | −51 to −55% |
GetProductReviews | 157–168 ms | 70–76 ms | −52 to −57% |
GetProductsByCategory | 279–317 ms | 198–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.
Control: cart calls did not change
Section titled “Control: cart calls did not change”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):
| Query | PHP-FPM run | Worker run |
|---|---|---|
AddProductsToCart | 499 ms | 505 ms |
GetCartDetails | 318 ms | 323 ms |
GetCartCrossSells | 317 ms | 347 ms |
RemoveItemFromCart | 254 ms | 298 ms |
| All 55 control calls | 325 ms | 345 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.
Where the time went
Section titled “Where the time went”- 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%.
Limits of the test
Section titled “Limits of the test”The tail is better, but rare spikes remain on both backends:
| PHP-FPM | FrankenPHP | |
|---|---|---|
| p95 | 495 ms | 330 ms |
| p99 | 947 ms | 605 ms |
| max | 1720 ms | 3826 ms |
The likely cause is the small test server, which also runs Magento cron. This was live browsing, not a controlled benchmark. Next steps:
- Replay the same query list on both backends, alternating, and compare p50 and p95.
- Match each spike to cron runs and to worker boot or recycle lines in the log.
- Size
GRAPHQL_WORKERSto peak bursts, so that extra threads rarely need to boot. - Keep cart and customer queries on PHP-FPM until they are tested for state safety, then consider
defaultmode.
Requirements
Section titled “Requirements”- FrankenPHP with thread-safe (ZTS) PHP 8.4 or later. The official
dunglas/frankenphpimages 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.phpas 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()ordie()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.
Edge cases
Section titled “Edge cases”| Situation | What 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. |
Who it applies to
Section titled “Who it applies to”- Production deployments with pre-compiled configuration.
- Full mode only after the verification gate passes with every installed feature.
Out of scope
Section titled “Out of scope”- 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.
Install
Section titled “Install”composer require magenxcommerce/module-graph-ql-app-serverbin/magento module:enable Magenx_AppServerbin/magento setup:upgradebin/magento setup:di:compile # production mode onlybin/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.
Glossary
Section titled “Glossary”| Term | Meaning |
|---|---|
| Worker | A long-lived process that starts the application once and serves many requests. |
| Request state | Data belonging to one request (customer, cart, store, parsed query). |
| Reset | Returning every tracked object to its freshly built state after a request. |
| Reset declaration | A list of object properties and their reset values for code that cannot reset itself. |
| Restricted mode | Worker serves only anonymous, read-only, allow-listed operations. |
| Full mode | Worker serves every API request. |
| Out of scope | A request the current mode does not serve; refused with a marker. |
| Replay | The web server re-sending a request to the classic server. |
| Recycle | Worker exits cleanly and a fresh one starts. |
| Traffic share | Percentage of API traffic sent to workers first. |
| State test | Runs each operation twice in one application and fails when any shared object changed. |