$down_time我知道這是一個(gè)常見錯(cuò)誤,很可能已經(jīng)得到解答,但我遇到的問題是,當(dāng)執(zhí)行該函數(shù)時(shí),當(dāng)新網(wǎng)站在此行離線時(shí),它會(huì)將變量返回為空,但是當(dāng)我運(yùn)行該函數(shù)$diff_in_seconds = $now_time->getTimestamp() - $down_time->getTimestamp();時(shí)再次在我的終端中出現(xiàn)錯(cuò)誤?;旧纤?down_time在更新到數(shù)據(jù)庫之前將變量返回為 null,我對(duì)此感到困惑,因?yàn)槭紫葓?zhí)行更新查詢。非常感謝您的幫助和指導(dǎo)。 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貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊
在網(wǎng)站的開頭想出了這個(gè) foreach 我定義了一個(gè)新變量,$time_now = date('Y-m-d H:i:s');然后在更新中使用它來查詢 down_at 時(shí)間并分配給$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 關(guān)注
- 130 瀏覽
添加回答
舉報(bào)
0/150
提交
取消