Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Cron
- {
- private $fileName;
- protected static $instance;
- public static function init($fileName = 'cache_cron')
- {
- if(!self::$instance) {
- self::$instance = new self( $fileName );
- }
- return self::$instance;
- }
- private function __construct($fileName)
- {
- $this->fileName = __DIR__ . DIRECTORY_SEPARATOR . $fileName;
- }
- private function __clone() {}
- public function runEvery($time)
- {
- if( !(file_exists($this->fileName) && ((filemtime($this->fileName) + $time) >= time())) ) {
- $this->setExecuted();
- return true;
- }
- return false;
- }
- public function setExecuted()
- {
- touch($this->fileName);
- }
- }
- // 5 - кол секунд для повторного выполнения
- if( Cron::init()->runEvery(5) ) {
- var_dump('Run baby run');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement