$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){
慕容森