...

Measuring PHP execution time separately from network and front-end performance

To distinguish between PHP execution time on the network and the front end, first measure a clearly defined code interval using hrtime() and compare it with the browser and server values for the same request. A single time value does not constitute a complete time record: The PHP timer also includes wait times within its interval, while browser timings have different limits. Server timing can transmit supplementary values, but does not measure them itself. You must take cache state, preliminary responses, and nested measurements into account when making comparisons.

What the current values actually show

A page that takes a long time to load can lose time in several places: while waiting for a response, in PHP, during database queries, or later during processing in the browser. A single value for the PHP Execution Time cannot distinguish between these causes. The key factor is which part of a specific request a measurement actually captures.

A PHP timer measures the elapsed time between two calls in the application code. If a database or API call occurs in between, its wait time is included in the measurement. The result is therefore not pure CPU time and does not provide any information about code that runs before the timer starts or after it ends.

The browser, on the other hand, observes events from its own perspective: for example, the start of a request and the arrival of a response. In the case of a dynamic document request, these events may be separated by network paths, proxy processing, and server-side processing. Which components are included depends on the specific events and the actual response path.

The HTTP Header Server timing It also transmits additional values that are determined by the application itself, for example. It does not automatically measure the entire server path. Furthermore, a value for a database call may fall within the application interval; in that case, the two numbers cannot be added together to calculate a total duration.

Compare the perspectives for the same request instead of treating them as a continuous timeline. A long application interval is a starting point for troubleshooting in the backend. A short interval combined with slow browser rendering, on the other hand, initially indicates only that the cause may lie outside this specifically measured section of code.

Specify the request and measurement conditions

First, select a specific route and the corresponding document request—for example, a store’s dynamic product page. Note whether you are testing a logged-in or anonymous state and what test data is being used. Otherwise, different shopping carts, permissions, or content could cause the application to behave differently.

Next, define the Measurement Limits: Where in the PHP code does the timer start, where does it end, and what database or API calls occur in between? Also note whether the measurement begins only after the framework has started. Only with this information can you later assess what a short or long value actually means.

Distinguish between cache hits and cache misses. If an upstream cache returns the response without PHP, some application logic may be missing; this does not prove that PHP processing took zero milliseconds. You should also track redirects as separate requests, rather than comparing their times to those of the final document without noticing.

Repeat the test under conditions that are as comparable as possible: the same browser, a similar connection, the same user state, and a documented cache status. A single run may yield unusual results due to temporary delays or a different response path. Therefore, record multiple results and their conditions instead of simply selecting the fastest result.

AI-generated stock image of two separate, blank index cards and a notebook on a desk
AI-generated illustrative image: Separately documented conditions make it easier to compare multiple requests.

For this exercise, you'll need browser developer tools and, for a PHP timer, access to the application code. Use a test environment or a path that has been approved for this purpose; production changes and load tests require appropriate approval. Web server logs or a profiler can supplement the analysis, but they are not required for every initial comparison.

Map the browser value and the server-side measurement to the same request, for example, using an identifier processed in compliance with data protection regulations. Do not collect any unnecessary personal data for this purpose, and limit access to diagnostic information. Without this association, even parallel requests or an interim cache update can skew the comparison.

Understanding Browser Timing Correctly

In the developer tools, open the Network tab and first select the document request for the navigation you're examining. The timing data for this request does not automatically include images, stylesheets, or subsequent API calls. Resource Timing provides a separate view for each of these individual resources; therefore, their processing in the browser is not fully accounted for either.

The Time requestStart marks the start of the request from the browser's perspective. responseStart indicates the beginning of a received response, while responseEnd marks the end of the response reception. The differences describe observed intervals; in particular, the time until the start of the response should not be equated with a PHP code interval.

At preliminary answers special caution is needed: An answer such as 103 Early Hints can already, even at responseStart be taken into account. Where the browser finalResponseHeadersStart When viewed in this light, this point in time helps us see the beginning of the final answer. The difference from requestStart Therefore, it should not be generally referred to as the wait time until the final HTML header.

Cache, service workers, redirects, and reused connections affect the path a request takes and how its metrics should be interpreted. For resources from other origins, certain metrics may be missing or set to zero if the appropriate permissions are not granted. Check these conditions before comparing two browser metrics.

If the browser wait time is high but the measured PHP interval is short, this does not necessarily indicate a network problem. Time can also elapse in a proxy or in a queue before the PHP measurement point. You should be especially cautious when making comparisons if PHP processing occurs only after a preliminary response: In that case, the two intervals have different boundaries.

Measuring PHP Code with hrtime

With hrtime(true) You measure the elapsed time between two points in the PHP code that you specify. The function uses a monotonic time base: For the duration, you calculate the difference between two calls instead of interpreting a single point in time as the elapsed time. The measured interval may also include wait times and is therefore not pure CPU time.

For the following example, create an isolated test file in a shared environment running PHP 7.3 or later. Access it via the web server so that you can then check the response header in the browser's developer tools. The placeholder represents the application section, the start and end of which you define yourself.

Code
<?php
$start = hrtime(true);

// Hier den zu untersuchenden Anwendungsteil ausführen.
$result = 'Testantwort';

$end = hrtime(true);

if ($start !== false && $end !== false) {
    $durationMs = ($end - $start) / 1000000;
    header('Server-Timing: app;dur=' . sprintf('%.3F', $durationMs), false);
}

echo $result;

The function returns the value in nanoseconds; dividing by one million yields the duration in milliseconds. On 32-bit systems, the return value may be a float. The error checking prevents a return value of false an invalid duration is returned. The unit "nanoseconds" alone does not guarantee the necessary measurement accuracy.

In this example, the interval ends before the header is set and before the output. Therefore, it does not capture these steps or any work that takes place before the first or after the second timestamp. If you set the start time only after the framework has started, its prior initialization will also be omitted from the result.

If you replace the placeholder with a database or API call, its wait time is included in the interval. A high value therefore initially indicates that the enclosed section took a long time; it does not yet distinguish between PHP calculations and waiting for other services. To make this distinction, you need additional, more closely spaced measurement points.

Transmit Measurement Values via Server Timing

The Header Server-Timing sends the specified metrics to the client. It does not measure the duration itself: the application or a server component involved must determine the value beforehand. For dur The specification recommends milliseconds; the name describes the metric, not necessarily its measurement limits.

In the PHP example, the header must be set before any output is actually sent. The second parameter false at header() adds another header field instead of replacing an existing field with the same name. In a framework, response middleware is often a suitable integration point, provided that the measurement has already been completed there and the headers have not yet been sent.

The following HTTP response header shows two fictitious values; it is not a measurement. Assuming that the database interval lies entirely within the application interval, then the values are nested. The 75 milliseconds for the database are already included in the 120 milliseconds for the application and should not be added to that total.

AI-generated illustration of a subinterval that lies entirely within a larger interval
AI-generated illustration: A database interval included in the calculation is not added to the application duration.
Code
Server-Timing: app;dur=120.000, db;dur=75.000

Under this assumption, the difference of 45 milliseconds simply describes the remaining time within app. It is not automatically PHP CPU time: it may also include other wait times. Therefore, for each metric, document where it begins and ends and whether it includes other intervals.

Only output carefully selected, sufficiently coarse-grained values. Metric names and descriptions may reveal infrastructure details; personally identifiable information does not belong in the header. Cross-origin access to timing data via JavaScript is restricted and can be controlled with Timing-Allow-Origin be controlled. You should specifically check for such authorization for the required sources.

Comparison of Measurement Intervals

The values in the table answer different questions. If possible, compare them for the same request and note the respective limits: An interval visible in the browser does not automatically start and end at the same points as a PHP timer or an NGINX log entry. It is also particularly important to Unit: Milliseconds and seconds must not be evaluated side by side without verification.

Metrics and Their Respective Limits
Measured variableStart and EndUnitWaiting Times and Restrictions
PHP Code IntervalBetween two self-called `hrtime` callsNanoseconds as a numerical value; often converted to millisecondsIncludes wait times within the section; does not include pure CPU time or a complete request.
Server Timing MetricDetermined by the measuring componentMilliseconds are recommended for thisReturns a calculated value; any waiting times included depend on the defined limits.
Browser Request IntervalrequestStart to responseStartMillisecondsIncludes the wait time observed from the browser's perspective; `responseStart` may capture a preliminary response.
Browser Response IntervalresponseStart to responseEndMillisecondsDescribes the observed response interval; do not confuse this with pure PHP execution.
NGINX Request TimeFirst read client bytes, then write to the log after sending the last bytesSecondsIncludes the request from NGINX's perspective, including wait times; the limits differ from those of the PHP timer.

Check the actual log format before interpreting a value as the duration of the entire backend process. The NGINX request time has its own timeframe: it begins as soon as the first client bytes are read and ends when the log entry is written after the last bytes are sent.

Browser and server timestamps can be used as complementary perspectives, but they should not be added together or subtracted from one another to create a complete timeline without first being verified. Measurement ranges may overlap, and client and server clocks are not reliably synchronized. Therefore, next to each value, note which request and which response path were actually observed.

Add Logs and PHP-FPM

An application timer displays only the code within the block. Additional Server logs help you view the same request from a different perspective. To do this, map the PHP value and the log entry using a request identifier assigned in compliance with data protection regulations. First, verify that the same response path was actually followed and that a redirect is not being confused with a separate request.

With NGINX, it begins $request_time It begins when the first client bytes are read and ends when the log is written after the last response bytes are sent. This duration has different limits than a timer within the PHP application and therefore should not be equated with it.

Check the configured log format and measurement limits before treating a log value as PHP runtime data. The Hosting Latency Analysis for the Network, PHP, and Database provides additional starting points for examining the entire response pathway.

Even when the visible response ends, that doesn't necessarily mean PHP's work is done. With fastcgi_finish_request() PHP-FPM can complete the response and then execute additional code. To assess the worker load, you therefore need additional server-side monitoring; a brief client-side response does not rule out further processing.

For streaming data or headers that have already been sent, a total value determined at a later time can no longer be reliably included in the original response header. Use appropriate logs or tracing for this purpose. Limit access and retention to what is necessary, and avoid including personally identifiable information or confidential content in metrics and correlation identifiers.

Narrow Down the Database, API, and Front End

If the application interval is long, break it down into smaller intervals at points that make technical sense. A separately measured database call can show how much elapsed time is contained within that call. From the application’s perspective, this value may also include connection and transmission times and should not be equated with the database’s pure processing time.

A long database result is a hypothesis for the next step, not a definitive diagnosis. Check the affected query using the available database diagnostic tools and its execution plan. Only then can you determine whether, for example, an inefficient access path or another cause is involved; the PHP timer alone does not prove that an index is missing.

For an external API, set another timer immediately after the outgoing call. A long API Interval shows where the application is waiting, but does not automatically explain why. Use detailed client timings or tracing, if available, to investigate whether name resolution, connection establishment, the remote end, or the data transfer is causing any issues.

If the HTML loads quickly but the page still seems slow, switch to the browser view. Examine the individual resource requests and then the JavaScript processing and rendering. The document’s PHP timer does not automatically track subsequent resource requests or the browser’s entire processing; you’ll need to make your own observations for these steps as well.

If a PHP value is missing, first check the Cache path: An upstream cache can return a response without invoking PHP for that request. Therefore, the absence of the header does not mean that PHP took zero milliseconds. Keep cache hits and dynamic responses separate, and compare only requests that are properly matched.

Evaluate and Further Review the Results

Before you draw conclusions based on unusual numbers, verify their association: Do the browser event, header, and log really belong to the same request? Otherwise, different user states, cache hits, or redirects can create apparent discrepancies. Also, document the ranges and units of each value before comparing multiple runs.

At nested intervals You must not add the part-time measurement to the total time. A difference between the application and the database is also not automatically PHP CPU time; it initially describes only the remaining elapsed time within the selected limits. Similarly, the difference between browser and application measurements is not necessarily pure network time.

If the identified performance bottleneck occurs repeatedly but the cause of the performance issue is still unknown, using a profiler is the next logical step. It can help you focus your investigation on specific functions and call paths. Be sure to specify which request and which section you are profiling, rather than applying the results to every page of the application.

However, when it comes to behavior under concurrent access, measuring a single request is not enough. Plan a reproducible application test under controlled conditions and take into account successful responses, errors, and response times. The article on Server CPU Benchmarking for Real-World PHP Workloads explains how to distinguish between a math problem and an application test.

Finally, be sure to include the work done after completing the answer in your evaluation: When using fastcgi_finish_request() A quick browser close may coincide with further PHP processing. Therefore, choose the next metric based on the specific question: visible response time, duration of a code block, or worker load are different objectives.

Sources and Current State of Knowledge

Status of the research:

Research status: November 13, 2026. The hrtime example requires PHP 7.3 or later; server timing is classified based on the W3C working draft dated November 2, 2026.

https://www.php.net/manual/en/function.hrtime.php

https://www.w3.org/TR/2026/WD-server-timing-20261102/

https://www.w3.org/TR/resource-timing/

https://www.php.net/manual/en/book.hrtime.php

https://www.php.net/manual/en/function.header.php

https://nginx.org/en/docs/http/ngx_http_log_module.html

https://www.php.net/fastcgi_finish_request

Current articles