| 1 |
<?php |
| 2 |
|
| 3 |
namespace WP_Defender\Component; |
| 4 |
|
| 5 |
use Calotes\Base\Component; |
| 6 |
|
| 7 |
class Timer extends Component { |
| 8 |
protected $clock; |
| 9 |
|
| 10 |
public function __construct() { |
| 11 |
$this->start(); |
| 12 |
} |
| 13 |
|
| 14 |
public function get_max_time() { |
| 15 |
$max = ini_get( 'max_execution_time' ); |
| 16 |
if ( ! filter_var( $max, FILTER_VALIDATE_INT ) ) { |
| 17 |
$max = 30; |
| 18 |
} |
| 19 |
|
| 20 |
return $max / 2; |
| 21 |
} |
| 22 |
|
| 23 |
public function start() { |
| 24 |
$this->clock = time(); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* @return bool |
| 29 |
*/ |
| 30 |
public function check() { |
| 31 |
$eslaped = time() - $this->clock; |
| 32 |
if ( ( $eslaped / 1000 ) >= $this->get_max_time() ) { |
| 33 |
return false; |
| 34 |
} |
| 35 |
|
| 36 |
return true; |
| 37 |
} |
| 38 |
} |