有一天,做日常接口開發,突然接口不行了,報錯:
[2020-02-15 15:12:57] local.ERROR: Handler:render {"class":"Illuminate\\Foundation\\Http\\Exceptions\\MaintenanceModeException","file":"D:\\qyPj\\OEM\\hans_online\\api-oem-test.qywww.com\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php","line":43,"message":"","code":0,"trace":""}
馬上找到vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode.php對應的43行:
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
*/
public function handle($request, Closure $next)
{
if ($this->app->isDownForMaintenance()) {
$data = json_decode(file_get_contents($this->app->storagePath().'/framework/down'), true);
throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']);
}
return $next($request);
}
}
43行是: throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']);
馬上查了了這個CheckForMaintenanceMode模式,叫做維護模式,
查看文檔:https://learnku.com/docs/laravel/5.5/configuration/1283#maintenance-mode
如下
維護模式
當應用程序處於維護模式時,所有對應用程序的請求都顯示爲一個自定義視圖。這樣可以在更新或執行維護時輕鬆地「關閉」你的應用程序。 維護模式檢查包含在應用程序的默認中間件棧中。如果應用程序處於維護模式,則將拋出一個狀態碼爲 503 的 MaintenanceModeException
異常。
要啓用維護模式,只需執行下面的 Artisan 命令 down
:
php artisan down
你還可以向 down 命令提供 message
和 retry
選項。其中 message 選項的值可用於顯示或記錄自定義消息,而 retry 值可用於設置 HTTP 請求頭中 Retry-After
的值:
php artisan down --message="Upgrading Database" --retry=60
要關閉維護模式,請使用 up
命令:
php artisan up
{tip} 你可以通過修改
resources/views/errors/503.blade.php
模板文件來自定義默認維護模式模板。
維護模式和隊列
當應用程序處於維護模式時,不會處理 隊列任務。而這些任務會在應用程序退出維護模式後再繼續處理。
維護模式的替代方案
維護模式會導致應用程序有數秒的停機(不響應)時間,因此你可以考慮使用像 Envoyer 這樣的替代方案,以便與 Laravel 完成零停機時間部署。
應該是我之前嘗試artisan命令時,運行了php artisan down命令
運行php artisan up,接口項目又可以了