$down_time我知道这是一个常见错误,很可能已经得到解答,但我遇到的问题是,当执行该函数时,当新网站在此行离线时,它会将变量返回为空,但是当我运行该函数$diff_in_seconds = $now_time->getTimestamp() - $down_time->getTimestamp();时再次在我的终端中出现错误。基本上它$down_time在更新到数据库之前将变量返回为 null,我对此感到困惑,因为首先执行更新查询。非常感谢您的帮助和指导。 public static function run() { $dept_emails = array( 19 => 'test@email.co.uk' ); $active_clients = Client::get_active_clients(); foreach ($active_clients as $client) { $websites = $client->websites; $services = $client->services; foreach ($websites as $website) { $website_url = $website->url; $website_url_parse = parse_url($website_url); $new_website_url = "https://" . $website_url; $website_status = Client::get_website_status($new_website_url); if(array_key_exists('host', $website_url_parse)) { $website_url = $website_url_parse['host']; } if($website_status == false) { $new_website_url = "http://" . $website_url; $website_status = Client::get_website_status($new_website_url); } $now = date('Y-m-d H:i:s'); $now_time = DateTime::createFromFormat('Y-m-d H:i:s', $now); $down_time = DateTime::createFromFormat('Y-m-d H:i:s', $website->down_at); $result = DB::update('clients_websites') ->set(array( 'last_checked' => $now )) ->where('id', '=', $website->id) ->execute(); if ($website_status) { // Website is back online, send email if($website->down_at != null && $website_status == true){
1 回答
慕容森
TA贡献1853条经验 获得超18个赞
在网站的开头想出了这个 foreach 我定义了一个新变量,$time_now = date('Y-m-d H:i:s');然后在更新中使用它来查询 down_at 时间并分配给$down_time变量。
$result = DB::update('clients_websites')
->set(array(
'down_at' => $time_now
))
->where('id', '=', $website->id)
->execute();
}
$down_time = DateTime::createFromFormat('Y-m-d H:i:s', $time_now);
- 1 回答
- 0 关注
- 78 浏览
添加回答
举报
0/150
提交
取消