VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/webtrees/app/Services/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/webtrees/app/Services/TimeoutService.php
<?php

/**
 * webtrees: online genealogy
 * Copyright (C) 2023 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

declare(strict_types=1);

namespace Fisharebest\Webtrees\Services;

use Fisharebest\Webtrees\Registry;

/**
 * Check for PHP timeouts.
 */
class TimeoutService
{
    //Long-running scripts run in small chunks
    private const TIME_LIMIT = 1.5;

    // Seconds until we run out of time
    private const TIME_UP_THRESHOLD = 3.0;

    // The start time of the request
    private float $start_time;

    /**
     * @param float|null $start_time
     */
    public function __construct(?float $start_time = null)
    {
        $this->start_time = $start_time ?? Registry::timeFactory()->now();
    }

    /**
     * Some long-running scripts need to know when to stop.
     *
     * @param float $threshold
     *
     * @return bool
     */
    public function isTimeNearlyUp(float $threshold = self::TIME_UP_THRESHOLD): bool
    {
        $max_execution_time = (int) ini_get('max_execution_time');

        // If there's no time limit, then we can't run out of time.
        if ($max_execution_time === 0) {
            return false;
        }

        $now = Registry::timeFactory()->now();

        return $now + $threshold > $this->start_time + (float) $max_execution_time;
    }

    /**
     * Some long-running scripts are broken down into small chunks.
     *
     * @param float $limit
     *
     * @return bool
     */
    public function isTimeLimitUp(float $limit = self::TIME_LIMIT): bool
    {
        $now = Registry::timeFactory()->now();

        return $now > $this->start_time + $limit;
    }
}

VaKeR 2022