Skip to content

Field Notes

NGINX 499 and PHP-FPM Failures in Kubernetes: A Practical Investigation

How to investigate NGINX 499 responses, PHP-FPM target-port mismatches, pod health, MySQL saturation and rollback paths in Kubernetes.

EmailLinkedIn
Kubernetes application request path and failure pointsClient / timeoutIngress NGINXService / portPHP-FPMMySQL / saturation
Kubernetes application request path and failure points
Symptom Likely cause Validation
Immediate upstream failure Port or endpoint mismatch Compare Service and FPM listeners
Slow intermittent 499s Worker or database pressure Correlate queue and query waits
Release-correlated errors Deployment regression Rollback and replay representative traffic
On this page

Environment covered: Kubernetes, NGINX ingress, PHP-FPM pods, services and MySQL-backed applications

During the reconstructed rollout below, static health checks succeed while PHP-backed requests fail. The useful split is between requests that cannot connect to the new FPM endpoint and requests that connect but outlast the client’s deadline.

NGINX uses 499 to record a client closing a connection before it can return the response. From that hop’s perspective, the client might be a browser, a load balancer or another proxy. The code says who stopped waiting; it does not say what kept them waiting.

This is a reconstruction of an anonymized NGINX, PHP-FPM and Kubernetes investigation. Names, ports and sample observations are illustrative, and the account does not establish that every 499 had one cause.

Separate a refused connection from a slow response

In this scenario, static pages remain available while PHP-backed requests fail intermittently during a rollout. Some proxy records show failed upstream connections. Others show requests that remain open until the client disconnects.

Those are related symptoms to investigate, not interchangeable error codes. A wrong port can produce a quick connect failure and a 502. A client giving up on a slow upstream can produce a 499. Combining both populations into one average hides the difference.

Select a few requests from each group. Correlate their times, routes, upstream addresses and release revisions. A cancellation from someone navigating away from a page is different from a growing population of slow requests during a deployment.

Reconstructed observations, not literal NGINX log records
Static health path: responds successfully
PHP request to new endpoint: connection refused
PHP request to another endpoint: client closes while upstream waits

The next question is whether the healthy signal exercised PHP at all.

Trace the request through the Service to the FPM listener

A pod can be Running because its container process exists. Its readiness probe can succeed because a static NGINX path returns 200. Neither proves the FastCGI connection works.

Follow the actual request path: ingress to web Service, web process to PHP Service, Service endpoint to the listener inside the PHP container. Check the process listener, not only the declared containerPort.

kubectl get pods,services -n app -o wide
kubectl get endpointslices -n app \
  -l kubernetes.io/service-name=php-runtime -o yaml
kubectl exec -n app deploy/php-runtime -- ss -lnt
kubectl exec -n app deploy/web -- nc -vz php-runtime 9000

The names and ports are synthetic. If an image lacks these utilities, use an approved debugging mechanism rather than installing tools into a production container during the incident. A TCP success proves reachability, not a valid FastCGI transaction; do not treat an HTTP curl request to an FPM port as an application check.

Correct the port contract in the deployment source

The illustrative mismatch is a Service forwarding to a port where the new PHP process does not listen. A named target can make the contract clearer, provided the pod declaration and actual process configuration agree.

# Illustrative Service port entry, not a complete manifest.
ports:
  - name: fastcgi
    port: 9000
    targetPort: php-fpm

The destination pod must declare the matching port name for the intended listener. Declaring it does not start a listener or rewrite FPM’s listen directive. Validate the rendered manifests and running process together, then fix the chart or configuration source so the next rollout cannot recreate the mismatch.

After repairing the port, inspect occupied FPM workers

Port wiring is an immediate fault in the retained investigation. The same account also describes worker and database pressure. It would be misleading to conclude that repairing the port automatically resolves every client disconnect.

Once NGINX can connect consistently, look at what occupies FPM workers. Its internal status information can show the listen queue, active workers and whether the pool reached pm.max_children. Keep that status endpoint internal and restricted; it is diagnostic infrastructure, not public content.

More workers are not automatically more throughput. If each worker is waiting on a saturated database, raising concurrency can increase memory demand and database contention while making the queue harder to recover from. Size the pool from measured worker memory and available capacity, including the master process and other runtime allocations.

Correlate worker waits with database activity

Compare worker occupancy with database activity during the same window. High database CPU, expensive SQL, long transactions and lock waits imply different remedies. A quiet PHP CPU graph can coexist with fully occupied workers waiting on a dependency.

SHOW FULL PROCESSLIST;
SHOW GLOBAL STATUS LIKE 'Threads_connected';
SHOW GLOBAL STATUS LIKE 'Slow_queries';

These outputs can contain private SQL and user data. Inspect them within the authorized environment and publish only sanitized interpretation. A cumulative counter is not a rate; compare observations over a known interval before drawing conclusions about a new release.

Container CPU throttling is another possible source of latency. Averaged utilization can conceal short periods at a limit. Correlate throttling, pod memory, queue growth and request duration rather than removing limits because the dashboard appears calm.

Timeout changes need a work budget

Write down the client’s deadline, any load-balancer limit, proxy timeouts and the application’s downstream deadlines. If an outer hop stops waiting first, NGINX may report the disconnect even though work continues deeper in the stack.

Extending the outer timeout can be appropriate for intentionally long operations with bounded capacity. It is a poor default repair for an unexplained queue. The change can retain more waiting connections and permit more duplicate work if clients retry.

For write operations, investigate retry and idempotency behavior too. A client cancellation does not prove the database transaction was cancelled. Replaying the request can duplicate an operation that finished after the client gave up.

Validate startup, steady state and termination

The repaired request path needs more than a single successful curl. Exercise representative routes while replacing a pod. Observe endpoint readiness, upstream errors, FPM queueing and database behavior through the transition.

Readiness should cover the runtime contract the pod can reasonably satisfy without turning every transient downstream outage into removal of the entire fleet. Termination needs its own plan: endpoint removal and process draining are related but not instantaneous guarantees that every in-flight request has finished.

Keep rollback available when the fault aligns with a release, but verify application and schema compatibility before using it. A quick application rollback must not introduce a slower data-integrity incident.

Retain separate observations for connect failures, upstream duration and client cancellation through the replacement test. The repaired port should eliminate its connection failures; persistent slow requests still require worker and dependency evidence. That distinction prevents a successful wiring repair from being reported as proof that every 499 is resolved.

Sources and further investigation

References support the protocol and product behavior discussed here; they are not evidence that the illustrative scenario occurred.

Continue the investigation

Need a second set of eyes?

Working through a similar production issue?

Discuss the technical context