Server IP : 104.21.14.48 / Your IP : 3.17.179.193 [ Web Server : Apache System : Linux b70eb322-3aee-0c53-7c82-0db91281f2c6.secureserver.net 6.1.90-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 2 12:09:22 EDT 2024 x86_64 User : root ( 0) PHP Version : 8.0.30.2 Disable Function : NONE Domains : 0 Domains MySQL : ON | cURL : ON | WGET : ON | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/chroot/var/www/wp-content/plugins/defender-security/src/component/ |
Upload File : |
<?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; } }