Compare commits
8 Commits
eff2dd273c
...
5463fd70b1
| Author | SHA1 | Date | |
|---|---|---|---|
| 5463fd70b1 | |||
| 54dd4bb7a6 | |||
| 71b35533f4 | |||
| 0814a3196f | |||
| 0db38ee30d | |||
| a3462f8493 | |||
| 05ef8b9316 | |||
| 95bafef52d |
@@ -1,7 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::get('/health', function () {
|
||||
$checks = ['db' => false, 'redis' => false, 'cache' => false];
|
||||
|
||||
try {
|
||||
DB::connection()->getPdo();
|
||||
$checks['db'] = true;
|
||||
} catch (\Throwable) {}
|
||||
|
||||
try {
|
||||
Redis::ping();
|
||||
$checks['redis'] = true;
|
||||
} catch (\Throwable) {}
|
||||
|
||||
try {
|
||||
cache()->put('health_check', 'ok', 5);
|
||||
$checks['cache'] = cache()->get('health_check') === 'ok';
|
||||
} catch (\Throwable) {}
|
||||
|
||||
$healthy = $checks['db'] && $checks['redis'] && $checks['cache'];
|
||||
|
||||
return response()->json([
|
||||
'status' => $healthy ? 'ok' : 'degraded',
|
||||
'timestamp' => now()->toIso8601String(),
|
||||
'environment' => app()->environment(),
|
||||
'php_version' => PHP_VERSION,
|
||||
'laravel' => app()->version(),
|
||||
'memory_mb' => round(memory_get_usage(true) / 1024 / 1024, 2),
|
||||
'checks' => $checks,
|
||||
], $healthy ? 200 : 503);
|
||||
});
|
||||
|
||||
Route::get('/', function () {
|
||||
return view('welcome');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user