Skip to main content
Home
GrN.dk

Main navigation

  • Articles
  • Cases
  • Services
  • Your Digital Project Manager
  • About Greg Nowak
  • Image Gallery
  • Contact
User account menu
  • Log in

Join my community / free newsletter — sign up here

Breadcrumb

  1. Home

Debugging PHP: A Practical Workflow for Faster Fixes

Illustrated infographic summarizing: Debugging PHP: A Practical Workflow for Faster Fixes

By Greg Nowak. Updated 7 August 2026.

PHP debugging gets expensive when the team starts changing code before it understands the failure. A broken checkout, missing webhook, or blank administration page may need only a small fix, but every hour spent guessing increases downtime, delivery risk, and client frustration.

The practical goal is to shorten the path from “something is wrong” to reliable evidence. That means reproducing the problem, choosing visibility appropriate to the environment, recording only useful context, and escalating to a step debugger when simpler tools stop paying off.

Define the failure before changing the code

Begin with a short incident description that another person can follow. Record the affected URL, command, queue, or integration; the expected and actual behaviour; when the problem began; and whether it affects every request or only particular accounts, inputs, or environments.

Then create the smallest repeatable case you can. Save a sanitized request body, note the order of actions, or isolate the failing command. Check recent deployments, configuration changes, dependency updates, and upstream service responses. This prevents a team from “fixing” an unrelated symptom while the original failure remains.

For production-only problems, do not experiment directly on arbitrary customer requests. Use request or correlation IDs to follow one known attempt through the application, web server, worker, and external integration.

Separate development visibility from production safety

In a local or restricted staging environment, set error reporting explicitly. This avoids relying on an old server image, hosting panel, or project default:

error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On

The same settings can be enabled at runtime for a narrow development investigation:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>

Runtime settings cannot reveal a parse error in the same file or another fatal failure that happens before those lines execute. For bootstrap and startup problems, change the relevant php.ini, PHP-FPM, web-server, container, or hosting configuration instead.

On public production systems, display nothing and log everything at the appropriate error level:

error_reporting = E_ALL
display_errors = Off
display_startup_errors = Off
log_errors = On

PHP’s production guidance favours logging over displaying errors. Raw errors can reveal paths, stack traces, configuration details, and business logic. If you configure a separate error_log file, confirm that the PHP process can write to it and that rotation, retention, and access permissions are managed. In container platforms, the existing SAPI or standard-error logging path is often easier to operate than an application-specific file.

Use logs to answer a specific question

A useful temporary log line should test a hypothesis: did the webhook arrive, which record was selected, which branch ran, or what status did the provider return? Include stable identifiers and decision points so related events can be followed without dumping an entire object.

<?php
error_log(sprintf(
    '[checkout] request_id=%s order_id=%s state=%s provider_status=%s',
    $requestId,
    $orderId,
    $state,
    $providerStatus
));
?>

Do not log access tokens, passwords, session cookies, payment details, or complete customer records. Even short-lived debug output can be copied into backups, observability systems, or agency support channels. If a secret is accidentally recorded, treat it as exposed: restrict access, remove retained copies where possible, and rotate the credential.

PHP’s error_log() can also append directly to a destination using message type 3. In that mode, PHP does not add a newline:

<?php
error_log(
    '[import] batch_id=' . $batchId . ' status=' . $status . PHP_EOL,
    3,
    '/path/outside-the-web-root/import-debug.log'
);
?>

Use direct-file logging only when the destination and permissions are controlled. The normal application or platform logger is usually a better long-term home.

Choose the least disruptive debugging tool

What you know Best first tool What it should establish
A local page is blank PHP error and startup-error configuration Whether parsing, bootstrap, or runtime execution failed
A live request fails intermittently Production logs with a request ID Which request, branch, and dependency produced the failure
The code receives the wrong shape or type A deliberate variable inspection Whether input, mapping, or type handling is responsible
The path crosses middleware, events, hooks, or workers Trigger-based Xdebug step debugging The actual execution path and the point where state changes
A PHP debugging decision matrix: start with the narrowest tool that can answer the next question.

Inspect variables without exposing them

var_dump() remains useful because it shows both type and value, including nested arrays and objects. That distinction matters when request data arrives as strings, database values are nullable, or an API changes its response shape.

<?php
var_dump($payload);
?>

Use it locally or in a tightly controlled environment. If you need to capture the output for comparison, PHP’s output-control functions can turn it into a string:

<?php
ob_start();
var_dump($payload);
$dump = ob_get_clean();
?>

From there, send only a sanitized excerpt to a protected debug destination. Do not leave dumps in templates, API responses, public directories, or client-facing screenshots.

Use Xdebug when logs cannot explain the path

Xdebug earns its place when the failure depends on several layers of state: framework middleware, event subscribers, legacy includes, dependency injection, queue workers, or repeated transformations. Configure it in a development environment and activate sessions only when requested:

xdebug.mode=debug,develop
xdebug.start_with_request=trigger

For a command-line run:

XDEBUG_TRIGGER=1 php your-script.php

The xdebug.mode setting belongs in php.ini or an Xdebug ini file loaded when PHP starts; reload the relevant PHP process after changing it. Xdebug also supports an XDEBUG_MODE environment override, but PHP-FPM and other server setups may filter environment variables. If the debugger does not connect, confirm the active configuration and network route before adding more breakpoints.

Finish with a safer system, not just a patch

After identifying the cause, make the smallest defensible fix and verify both the failing case and a normal path. Remove temporary logs and dumps, disable investigation-only settings, and confirm that no debug files are publicly reachable.

Then preserve the lesson as a regression test, validation rule, monitoring signal, deployment check, or short runbook entry. That is what turns one successful fix into lower operational risk for the next release.

If production-only failures, unclear handoffs, or fragile releases keep consuming agency time, Greg can help improve both the PHP debugging process and the delivery workflow around it.

Related on GrN.dk

  • How to Check Whether a PHP Constant Is Defined (Without Breaking Production)
  • NGINX 1.30 changed upstream connection reuse: what to check before you upgrade
  • Cloudflare Service Keys Stop in September: Find Every Caller

Need help with this kind of work?

Discuss your PHP delivery workflow Get in touch with Greg.

Sources

  • PHP: Runtime Configuration
  • PHP: error_log
  • PHP: var_dump
  • Xdebug: Step Debugging
Last modified
2026-08-12

Tags

  • php
  • Debugging
  • Xdebug
  • Error Logging
  • Web Operations
  • Log in to post comments

Review Greg on Google

Greg Nowak Google Reviews

 

Written recommendations from Trafik og Veje, Aarhus Municipality (2011) and AgroTech (2010) — read them on LinkedIn.

Illustrated infographic summarizing: From Supplier Invoice to Bookkeeping: AI with a Control Checkpoint
From Supplier Invoice to Bookkeeping: AI with a Control Checkpoint
2026-08-18

AI can reduce the work involved in processing supplier invoices, but reliable bookkeeping requires validation, duplicate checks, approval and a clear audit trail.

Illustrated infographic summarizing: Nginx 1.30 Changed the Upstream Defaults—Test Before You Upgrade
Nginx 1.30 Changed the Upstream Defaults—Test Before You Upgrade
2026-08-17

Nginx 1.30 defaults upstream proxying to HTTP/1.1 with keepalive enabled. Here is what to inspect, model and test before upgrading.

Illustrated infographic summarizing: OpenAI’s Assistants API Shuts Down in Ten Days. Is Your App Ready?
OpenAI’s Assistants API Shuts Down in Ten Days. Is Your App Ready?
2026-08-16

OpenAI’s Assistants API shuts down on August 26, 2026. Learn what to inventory, how to preserve state and how to cut over without breaking the product.

Illustrated infographic summarizing: WordPress 7.1 Forces the Editor Into an iframe—Test Your Custom Blocks
WordPress 7.1 Forces the Editor Into an iframe—Test Your Custom Blocks
2026-08-15

WordPress 7.1 removes the non-iframe editor fallback. Learn how to audit custom blocks, test real workflows and fix compatibility issues before launch.

Illustrated infographic summarizing: GitHub will stop sending jobs to stale self-hosted runners
GitHub will stop sending jobs to stale self-hosted runners
2026-08-14

GitHub starts enforcing runner versions on August 24, 2026. Audit and upgrade self-hosted runners before builds and deployments start stalling.

Illustrated infographic summarizing: Your AI Agent Has Shell Access. What Can It Reach?
Your AI Agent Has Shell Access. What Can It Reach?
2026-08-13

A practical guide to mapping what a shell-enabled AI agent can reach, then containing its access to files, credentials, networks, tools, and high-impact actions.

Illustrated infographic summarizing: Cloudflare Changed DoH JSON. What Else Is Parsing DNS as Text?
Cloudflare Changed DoH JSON. What Else Is Parsing DNS as Text?
2026-08-12

Cloudflare’s DoH JSON change exposes brittle DNS parsing. Find affected scripts, test both formats, and choose a safer integration contract.

Illustrated infographic summarizing: Your Website Can Answer Questions Now. Should It?
Your Website Can Answer Questions Now. Should It?
2026-08-11

NLWeb makes conversational website search practical to deploy. The real question is whether your content, users and team are ready to support it.

Illustrated infographic summarizing: AI Search Finally Has Reports. Now Connect Visibility to Revenue
AI Search Finally Has Reports. Now Connect Visibility to Revenue
2026-08-11

Google and Bing now expose first-party AI search data. The real task is connecting citations and impressions to analytics, CRM outcomes, and revenue.

Illustrated infographic summarizing: The Bot Passed Your CAPTCHA. What Did It Do Next?
The Bot Passed Your CAPTCHA. What Did It Do Next?
2026-08-11

Passing a challenge is only one signal. Session analysis, server-side validation and endpoint-specific controls help reduce bot abuse without blocking customers.

More articles

Built by AI — available for your business. The daily articles on this site are researched, written and illustrated by an autonomous AI pipeline. At nowa.dk I install the same kind of AI automation in businesses at fixed prices — site in Danish, English version here, and web/marketing agencies have a dedicated page.

RSS feed

Footer

  • All articles
  • Contact

GrN.dk — AI automation, web platforms, web optimization, data handling and logistics.

© 2026 GrN.dk · LinkedIn · Contact · AI automation in Danish: nowa.dk

Behind GrN.dk: Individual Entrepreneur Codecrafter · Tax ID 305669096 · Bakhtrioni St. 22, 0194 Tbilisi, Georgia · official business register