Every minute, cron performs a check for 20 minutes or not. On the local server, everything works fine, on the working server in the 1st minute immediately performs an action, the code is identical.
I thought that the problem is the difference in the time of php and mysql, but after checking the time on both servers, they are the same, the only thing that is on the local time is UTC, but on the worker in Kiev.
The class returns the time difference:
class Time extends Model { private $now; public function __construct(array $config = []) { $this->now = new \DateTime('now'); parent::__construct($config); } public function getTimeDiffNow($date) { return date_diff($date, $this->now); } Called in the following construction:
/** * @return array * @throws \yii\db\Exception */ public function getArrayOfBooking() { $sql = "SELECT id, created FROM booking WHERE status = 2"; return Yii::$app->db->createCommand($sql)->queryAll(); } /** * @param int $period * @return array * @throws \yii\db\Exception */ public function checkPeriod($period = self::PERIOD_STATUS_WFP) { $arr = []; foreach ($this->getArrayOfBooking() as $book) { $time = new Time(); $date = new \DateTime($book['created']); $minutes = $time->getTimeDiffNow($date)->format('%i'); $arr[] = ($minutes > self::PERIOD_STATUS_WFP) ? $book['id'] : false; } return $arr; }