Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,212 of 9,212 pages
About the help in other languages
All help pages

Operations: switching on, monitoring, logs, troubleshooting and tuning

What this is. Everything an operator needs to run the headless features in production: switching the API on per siteaccess, the files it keeps, what to monitor, where the logs are, a table of common errors with their…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/headless/operations.md

On this page

Operations: switching on, monitoring, logs, troubleshooting and tuning

What this is. Everything an operator needs to run the headless features in production: switching the API on per siteaccess, the files it keeps, what to monitor, where the logs are, a table of common errors with their fixes, and performance tuning.

When to use it. When you set up an installation for API clients, watch it, answer a client's error report, or make it faster.

Quick example: is the API on, and is it healthy?

./console exp:graphql:status --siteaccess=site
siteaccess     site
enabled        yes
mutations      yes
end point      /api/graphql
library        webonyx/graphql-php 15.43.0
limits         depth 12, complexity 1000, list 100 (default 25)
rate limits    600 per user or key, 120 per anonymous address, in 60 s
persisted      enabled, 1 stored, automatic: signed-in, persisted only: disabled
cache          persisted queries, at most 86400 s
introspection  signed-in
naming         identifier
schema         fd661f82e524, 92 classes, 894 fields
extensions     eztags/1 explayouts/1 migration/1 expwt/1 cjw_newsletter/1 cjw_newsletter/events/1
string only    cjwnewsletteredition cjwnewsletterlist cjwnewsletterlistvirtual
event kinds    newsletter.subscription.confirmed (cjw_newsletter/events/1) object; fields listId:int status:string
PASS the GraphQL API can run

Contents

  1. Switching the API on
  2. A read-only public siteaccess
  3. Checklist before go-live
  4. The files the API keeps
  5. Monitoring
  6. Logs and the audit
  7. Finding a request by its id
  8. Troubleshooting: common errors and fixes
  9. Performance tuning
  10. Several servers
  11. Velocity
  12. Backups and disaster recovery
  13. Console commands

Switching the API on

The API is off until it is switched on (graphql.ini [GraphQLSettings] Enabled=disabled). It needs the library webonyx/graphql-php 15 (composer require webonyx/graphql-php:^15.32.3, suggested by the kernel's composer.json); without it /api/graphql answers 503 and everything else of Exponential works as before.

./console exp:graphql:enable                                             # what would change (a diff), nothing written
./console exp:graphql:enable --siteaccess=site --apply                   # on, in the siteaccess site only
./console exp:graphql:enable --siteaccess=site --origin=https://shop.example.com --key-for=frontend --apply

exp:graphql:enable writes settings/override/graphql.ini.append.php (Enabled=enabled, the siteaccess into SiteAccessList[]), with --origin the CORS settings of rest.ini, with --key-for a personal API key (shown once; --key-limited, --key-public, --scope, --days), checks that the schema builds, backs up every file it changes, clears the INI caches, and prints the end point, a curl example and the playground. Or do it in Setup > GraphQL (policy graphql/administrate).

By hand:

# settings/override/graphql.ini.append.php
[GraphQLSettings]
Enabled=enabled
SiteAccessList[]
SiteAccessList[]=site
php bin/php/ezcache.php --clear-tag=ini --allow-root-user
curl -s https://www.example.com/api/graphql -H 'Content-Type: application/json' -d '{"query":"{ siteaccess { name } }"}'

SiteAccessList[] empty means every siteaccess. Each siteaccess can override any setting in settings/siteaccess/<name>/graphql.ini.append.php; settings/override/ wins over both.

Off again: ./console exp:graphql:disable --apply (every siteaccess), or --siteaccess=<name> to take one out of the list. /api/graphql then answers 404 DISABLED; persisted queries, keys and the cache stay.

A read-only public siteaccess

./console exp:graphql:disable --siteaccess=site --mutations --apply      # MutationsEnabled=disabled there

For a public siteaccess also consider:

# settings/siteaccess/site/graphql.ini.append.php
[GraphQLSettings]
MutationsEnabled=disabled
Introspection=signed-in
PersistedQueriesOnly=anonymous
AutomaticPersistedQueries=signed-in
Subscriptions=disabled
Debug=disabled

PersistedQueriesOnly=anonymous lets visitors run only the queries you stored; signed-in programs (your build, your SSR server with a key) can still send anything.

Checklist before go-live

  1. The library is installed and exp:graphql:status --siteaccess=<public> says PASS.
  2. The API is on only in the siteaccesses that need it.
  3. The role Anonymous reads only what the public may see; check with an anonymous request of a protected node (null expected).
  4. Mutations are off on public siteaccesses unless needed; writing keys belong to dedicated users with narrow policies.
  5. Keys are limited to siteaccesses and have an expiry; a rotation date is in the calendar.
  6. Introspection=signed-in, Debug=disabled.
  7. CORS lists exactly the front end's origins, and ExposedHeaders[] what the client reads.
  8. The request shield exempts /api/** from the browser check and gives the API a budget (CORS, rate limits and the request shield).
  9. Trusted proxies are configured, so rate limits count visitors, not the proxy.
  10. Persisted queries are stored by the deployment (exp:graphql:persist queries/ --apply), and the response cache answers them (X-GraphQL-Cache: HIT on the second request).
  11. Webhooks: exp:graphql:webhooks --test=<name> --apply passes; the cron part graphqlwebhooks runs (the frequent group); ClassList[] set for external receivers.
  12. Subscriptions: limits fit the PHP-FPM pool; proxies do not buffer /api/graphql/subscribe.
  13. Monitoring of the items below is in place.
  14. exp:graphql:bench against the public end point meets the targets.

The files the API keeps

var/<site> is the installation's var directory (var/site by default); var/cache is the cache directory.

PathWhatSafe to delete?
var/cache/graphql/responses/the response cache, and the expired markeryes (ezcache --clear-id=graphql)
var/cache/graphql/credentials/remembered rights of keys and tokensyes
var/cache/graphql/rate/rate-limit countersyes (limits restart)
var/<site>/graphql/persisted/stored persisted queries (<sha256>.graphql, names.json)no: clients call them; back it up
var/<site>/graphql/events/the event journal (events-<n>.jsonl)not while receivers are behind; rotation removes old files
var/<site>/graphql/webhooks/cursor.jsonwhere the webhooks read nextno (deleting it skips to the end)
var/<site>/graphql/webhooks/outbox/deliveries waitingno
var/<site>/graphql/webhooks/failed/deliveries that gave upafter review
var/<site>/graphql/webhooks/deliveries.jsonl (.1.jsonl)the delivery logrotated by size
var/<site>/graphql/subscriptions/the open subscriptions (for the limits)stale files only

Files are written by both the PHP-FPM user and (with Velocity) root; they take the owner and group of their directory. Keep the directories writable by the web server's user.

Monitoring

WhatHowAlert when
The API answerscurl -s -o /dev/null -w '%{http_code}' -H 'Content-Type: application/json' -d '{"query":"{ siteaccess { name } }"}' https://www.example.com/api/graphqlnot 200
The cache worksthe share of X-GraphQL-Cache: HIT in the access log (log the header)drops sharply
Latencyexp:graphql:bench daily; your APMcached rows over 33 ms
ErrorsINTERNAL in answers; var/log/error.log lines of expGraphQL*any
Rate limits429 in the access log, by key and addressrising
Webhook backlogfiles in var/<site>/graphql/webhooks/outbox/above a few hundred, or not shrinking
Webhooks given upnew files in failed/, gave-up in deliveries.jsonlany
Journal lagthe webhooks' cursor.json position versus the end of the newest journal filefar behind for long
Subscriptionsfiles in var/<site>/graphql/subscriptions/; busy PHP-FPM workersnear MaxSubscriptions or pm.max_children
Keysexp:graphql:keys --list --format=json: keys expiring within 14 days, never usedexpiring, unused for long
Refusalsthe audit: access.apikey.use.failed by reasonbursts of secret/unknown
Libraryexp:graphql:status exit codenot 0

A small check script for cron or your monitoring agent:

#!/usr/bin/env bash
# exp-graphql-health: PASS/FAIL lines, exit 1 on any FAIL
R=/path/to/installation; SITE=site; URL=https://www.example.com/api/graphql; rc=0
code=$(curl -s -o /dev/null -w '%{http_code}' -m 10 -H 'Content-Type: application/json' -d '{"query":"{ siteaccess { name } }"}' "$URL")
[ "$code" = 200 ] && echo "PASS api $code" || { echo "FAIL api $code"; rc=1; }
out=$(ls "$R/var/$SITE/graphql/webhooks/outbox" 2>/dev/null | wc -l)
[ "$out" -lt 500 ] && echo "PASS outbox $out" || { echo "FAIL outbox $out"; rc=1; }
failed=$(find "$R/var/$SITE/graphql/webhooks/failed" -name '*.json' -mmin -60 2>/dev/null | wc -l)
[ "$failed" = 0 ] && echo "PASS failed/ last hour 0" || { echo "FAIL failed/ last hour $failed"; rc=1; }
exit $rc

Logs and the audit

LogHas
var/log/error.log (and var/<site>/log/)PHP exceptions behind INTERNAL errors (expGraphQLServer::formatError writes the class, message, file and line), library problems
the web server's access logevery request; add X-Request-Id, X-GraphQL-Cache and the status to its format
var/<site>/graphql/webhooks/deliveries.jsonlevery webhook attempt: time, delivery, end point, event, status, ms, result, error
the audit (Setup > Audit trail)content.graphql.mutation, content.graphql.mutation.failed (with the reason: get, anonymous, scope, form_token, a policy refusal, an error), access.apikey.create, .revoke, .use (first use), .use.failed (with the reason)
Setup > GraphQLthe state, the cache, persisted queries, keys, webhooks and their last deliveries
Setup > Job queuejobs of Delivery=queue, the dead letter
Setup > Request shieldrequests the shield refused or checked

Debug=enabled (development only) puts the exception and trace into extensions.debug of the answer.

Finding a request by its id

Every answer has a request id (X-Request-Id, extensions.requestId, 16 hexadecimal characters). Ask clients to quote it. Then:

grep -r 'a1b2c3d4e5f60718' /var/log/nginx/ /path/to/installation/var/log/ 2>/dev/null

Errors of the code are logged with the request's context; with the id in your access-log format you find the exact request, its time, its client and its status.

Troubleshooting: common errors and fixes

SymptomCauseFix
404 {"errors":[{"message":"The GraphQL API is switched off in this siteaccess.","extensions":{"code":"DISABLED"}}]}Enabled=disabled, or the siteaccess is not in SiteAccessList[], or the request landed in another siteaccessexp:graphql:enable --siteaccess=<name> --apply; check the host or X-Siteaccess (an unknown name is ignored)
503 "The GraphQL library is not installed."webonyx/graphql-php missing or not version 15composer require webonyx/graphql-php:^15.32.3; or graphql.ini LibraryPath/GRAPHQL_LIBRARY_PATH
404 for /api/graphql with an HTML pagethe request did not reach index_rest.phpthe web server's rewrite rules for /api/ (as for the REST API)
401 {"error":"invalid_token"}key wrong, revoked, limited to another siteaccess, owner disabled; or a key in the URLcheck the key (exp:graphql:keys --list), the siteaccess, the header
401 expired_tokenkey or OAuth token expireda new key; refresh the token
403 insufficient_scopekey without graphql:read, or the owner lost content/reada key with the scope; give the role back
429 {"error":"rate_limited"}rest.ini [ApiKeySettings] RateLimitPerMinuteraise it; for a public key set 0
429 RATE_LIMITEDthe GraphQL rate limithonor Retry-After; raise the limit; trusted proxies
429 with Request-Shield-Challengethe shield's browser checkchallenge-exempt /api/**
a key seems ignored, signedInBy: anonymousthe web server drops Authorizationpass it through to PHP
INTROSPECTION_DISABLEDanonymous introspection, or contentClasses anonymouslysign in; use exp:graphql:schema on the console
VALIDATION "Cannot query field ..."a field not in the schema: hidden, a class excluded, another naming style, another siteaccessexp:graphql:schema --format=summary --siteaccess=<name>
a node is nullnot there, or the user may not read it, or its class is not in the schemacheck with --as=<login> on the console; check ClassList[]
COMPLEXITY_LIMITnested lists with large limitssmaller limit, separate requests, or MaxComplexity
DEPTH_LIMITvery deep nestingflatten; MaxDepth
PERSISTED_QUERY_NOT_FOUNDthe query was not stored in this installation, or on this serverexp:graphql:persist queries/ --apply on every server (or share var/<site>/graphql/persisted/)
PERSISTED_QUERY_REQUIREDPersistedQueriesOnlypersist the query and send its id
X-GraphQL-Cache never HITad-hoc queries (always BYPASS); answers with errors; currentUser in a signed-in query; Debug=enabled; constant publishing; query string order variesuse persisted queries with stable variables
old content after a publishyour own cache or CDN not purgedcheck the webhook delivery log and your receiver
FORBIDDEN "Sign in to change content."mutation without credentialsa key with graphql:write
FORBIDDEN "You may not do this to this content."the owner's policiesgive the role the policy for that class/section/subtree
PENDING after a mutationa workflow (approval) holds itapprove in the administration
BAD_USER_INPUT "The value of the field ... could not be stored."the datatype refused the stringsee Datatypes in GraphQL
upload refusedMaxUploadSize, PHP's upload_max_filesize/post_max_size, an upload checkraise the limits consistently
webhooks not sentthe cron part does not runruncronjobs.php -q frequent in cron
subscription stream closes at onceproxy buffering, max_execution_time, Velocity StreamTimeoutX-Accel-Buffering: no passes through; timeouts above SubscriptionMaxDuration
Internal server error (INTERNAL)a bug or a broken datatypethe error log with the request id; report it

Performance tuning

What a request costs.

RequestCost
cached persisted query, early answera file read; no settings, no database; target under 13 ms
304 of a cached persisted queryless
persisted query, cache missthe kernel starts, the schema loads from its cache, the query runs
ad-hoc querythe same, every time
mutationthe kernel's operations: publish, workflows, caches, the journal
subscriptionone process for up to SubscriptionMaxDuration seconds, a database connection per event sent

Measure with the console:

./console exp:graphql:bench --url=https://www.example.com/api/graphql --id=articles
./console exp:graphql:bench --url=https://www.example.com/api/graphql --id=articles \
    --variables='{"limit":50}' --query-file=queries/articles.graphql --requests=200 --runs=3
GRAPHQL_BENCH_TOKEN=$KEY ./console exp:graphql:bench --url=... --id=articles --rows=get,post,kernel

Rows: get (cached GET), 304, post (cached JSON POST), kernel (a form POST, which starts the kernel), uncached (an ad-hoc query). Cached answers must come within 33 ms (hard limit), with targets of 20 ms and then 13 ms for the median and p95. Exit code 1 when a cached row is over the limit.

Levers, most effective first:

  1. Persisted queries for every public page. They are cached and answered before the kernel starts.
  2. Stable request shapes. The cache key includes the query string as sent: always build it the same way (id then variables, the same JSON key order).
  3. Fewer, wider queries. Aliases and fragments instead of several requests; the batch loader fetches a whole level of relations, owners and parents at once, so a page of 50 articles with authors costs a few queries.
  4. Small pages. limit/first as small as the page shows; never nest lists without need.
  5. ETag/304 in clients.
  6. Your own cache in the front end, purged by tags (Cache tags and invalidation).
  7. Velocity (persistent workers) for uncached requests: no bootstrap per request.
  8. Search with Solr (ezfind) on large installations; the kernel's own search engine queries the database.
  9. Image aliases made ahead (after publishing, by the job queue: image.alias.generate) so a first request does not wait for one.
  10. OPcache with enough memory for the kernel and the schema classes.

Settings that trade safety for speed:

SettingEffect
CredentialCacheTtl highermore signed-in requests answered early; a revoked token reads cached answers for that long (keys are forgotten at once when changed)
ResponseCacheTtlonly matters without publishes; 0 keeps entries until the next expiry
MaxComplexity, MaxListLimit higherbigger queries allowed; more load per request
SubscriptionPollInterval lowerfaster events, more file reads per open stream

Several servers

On several web servers behind a load balancer:

  • Persisted queries must exist on every server: store them on each (part of the deployment), or share var/<site>/graphql/persisted/ (the DFS cluster's shared storage, or a shared mount).
  • The response cache, credential cache and rate counters are per server unless var/cache/graphql/ is shared. A per-server cache is fine; rate limits then count per server (the effective limit is multiplied by the number of servers).
  • The journal must be one: share var/<site>/graphql/events/ (and webhooks/, subscriptions/) between servers, or a publish on server A is invisible to subscriptions on server B and to the webhooks run on B. Run the cron part graphqlwebhooks on one server only (the lock file is per directory: on a shared directory two servers are safe too).
  • Expiry: a publish on A expires A's response cache; B's expires when B clears its own view caches (cluster handlers propagate them) or after ResponseCacheTtl.
  • Keys are in the database: shared by definition. The key limit of rest.ini (APCu) is per server.

Velocity

Under Velocity (Exponential's persistent-worker server) the API behaves the same, with three differences:

  • Uncached requests are faster (no bootstrap). A changed kernel class or setting reaches the workers only after exp:velocity restart (deploy with exp:velocity deploy).
  • Subscriptions are also available as WebSockets (graphql-transport-ws); Velocity's bridge opens the SSE stream for each. Each open stream holds a worker within StreamShare; SubscriptionMaxDuration must stay below Velocity's StreamTimeout (300 s).
  • Files under var/ may be written by root (Velocity) and the site user (PHP-FPM); the API makes them take the owner and group of their directory.

Backups and disaster recovery

Back upWhy
the databasekeys (expapikey), content, the audit
var/<site>/graphql/persisted/clients call these queries by name
settings/override/graphql.ini.append.php, rest.ini.append.phpthe switches, webhooks, CORS
the secret store (Setup > Secrets) and EXP_SECRET_KEY / var/secrets/exp_secret.keywebhook signing secrets; preview tokens depend on the secret key
the request shield rulesyour API rules

Not needed: the response cache, the rate counters, the journal (after a restore, receivers should resynchronize by a full walk), the outbox (lost deliveries can be replayed from the journal if it survived).

After a restore of an older database: keys made after the backup no longer exist (401), keys revoked after it are valid again: revoke them anew.

Console commands

CommandDoes
exp:graphql:enable / exp:graphql:disableswitch the API or the mutations on and off per siteaccess, CORS origins, a key
exp:graphql:statusthe state, library, limits, schema hash, classes, string-only datatypes, extensions, event kinds
exp:graphql:schemathe schema: sdl, json or summary, --output
exp:graphql:queryrun a query as a user (--as), a file, a persisted query (--id), --format=table
exp:graphql:persistcheck, store, list and remove persisted queries
exp:graphql:keyslist, create and revoke API keys with GraphQL scopes
exp:graphql:webhookslist, add, remove, test webhooks; deliver; the log
exp:graphql:starterwrite a starter front end (html, next, nuxt, astro, expo)
exp:graphql:benchmeasure the end point
php bin/php/ezcache.php --clear-id=graphqlexpire the response cache

Every command that changes something shows what it would do and writes only with --apply.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x