# jetpack/16.3-a.7/vendor/wp-php-toolkit/reprint-server/src/class-resource-budget.php

Jetpack – WP Security, Backup, Speed, &amp; Growth, version 16.3-a.7. 56 lines.

- Page: https://pluginprobe.com/plugins/jetpack/16.3-a.7/code/vendor/wp-php-toolkit/reprint-server/src/class-resource-budget.php
- Raw: https://pluginprobe.com/plugins/jetpack/16.3-a.7/raw/vendor/wp-php-toolkit/reprint-server/src/class-resource-budget.php
- Modified: 2026-09-08T18:39:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/jetpack/16.3-a.7/code/vendor/wp-php-toolkit/reprint-server/src/class-resource-budget.php#L10-L20`.

```php
<?php

// Declared here rather than in export.php so it can live in this package's
// namespace. export.php is a global-namespace file of endpoint functions that
// callers reach by unqualified name.

namespace WordPress\Reprint\Server;

/**
 * Tracks time and memory limits for a single API request.
 *
 * Every export endpoint runs under resource constraints — a maximum
 * execution time and a memory ceiling.  Rather than threading four
 * separate values through every function signature and every
 * should_continue() call, this class bundles them into a single
 * object with a simple has_remaining() check.
 */
class ResourceBudget
{
    /** @var float */
    public $start_time;
    /** @var int */
    public $max_time;
    /** @var int */
    public $max_memory;
    /** @var float */
    public $memory_threshold;

    public function __construct(
        float $start_time,
        int $max_time,
        int $max_memory,
        float $memory_threshold
    ) {
        $this->start_time = $start_time;
        $this->max_time = $max_time;
        $this->max_memory = $max_memory;
        $this->memory_threshold = $memory_threshold;
    }

    /** Returns false when the request should yield due to time or memory pressure. */
    public function has_remaining(): bool
    {
        if (microtime(true) - $this->start_time >= $this->max_time) {
            return false;
        }

        $memory_used = memory_get_usage(true);
        if ($memory_used >= $this->max_memory * $this->memory_threshold) {
            return false;
        }

        return true;
    }
}

```
