# Server-Timing Header for Administrators

> Adds a Server-Timing header with PHP time, database query count and peak memory to pages viewed by administrators, so you can read the numbers in your browser's developer tools Network tab.

- Type: PHP
- Runs: Run everywhere
- Category: [Performance](https://wpide.com/library/category/performance/)
- Tags: debugging, headers, monitoring
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/perf-server-timing-header/

## Code

```php
$wpide_server_timing = function () {
    if ( headers_sent() || ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
        return;
    }

    header( sprintf(
        'Server-Timing: php;dur=%.1f;desc="PHP until the template starts", db;desc="%d queries", mem;desc="%s peak memory"',
        timer_float() * 1000,
        get_num_queries(),
        size_format( memory_get_peak_usage( true ), 1 )
    ) );
};

// Sent just before the page template (or admin screen) starts rendering.
add_action( 'template_redirect', $wpide_server_timing, PHP_INT_MAX );
add_action( 'admin_init', $wpide_server_timing, PHP_INT_MAX );
```

## Notes

Visitors never receive the header; the time covers everything WordPress does before the page template starts rendering.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Server-Timing Header for Administrators" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
