HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux WebLive 5.15.0-79-generic #86-Ubuntu SMP Mon Jul 10 16:07:21 UTC 2023 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: 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,
Upload Files
File: /var/www/html/wpdeskera/wp-content/plugins/defender-security/src/component/class-timer.php
<?php
/**
 * Handles time related tasks.
 *
 * @package WP_Defender\Component
 */

namespace WP_Defender\Component;

use Calotes\Base\Component;

/**
 * Handles time related tasks.
 */
class Timer extends Component {

	/**
	 *  The start time of the timer.
	 *
	 * @var int
	 */
	protected $clock;

	/**
	 * Constructor initializes and starts the timer.
	 */
	public function __construct() {
		$this->start();
	}

	/**
	 * Retrieves the maximum execution time allowed for scripts, halved.
	 *
	 * @return int The half of the maximum execution time in seconds.
	 */
	public function get_max_time() {
		$max = ini_get( 'max_execution_time' );
		if ( ! filter_var( $max, FILTER_VALIDATE_INT ) ) {
			$max = 30;
		}

		return $max / 2;
	}

	/**
	 * Starts or restarts the timer.
	 *
	 * @return void
	 */
	public function start(): void {
		$this->clock = time();
	}

	/**
	 * Checks if the elapsed time has exceeded half of the maximum execution time.
	 *
	 * @return bool True if the current elapsed time is less than half of the max execution time, false otherwise.
	 */
	public function check(): bool {
		if ( ( $this->get_difference() / 1000 ) >= $this->get_max_time() ) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the difference in seconds from when the timer was started to the current time.
	 *
	 * @return int The time difference in seconds.
	 */
	public function get_difference(): int {
		return time() - $this->clock;
	}
}