1. ゼロダウンタイムの導入
# Deployer (deployer.org)
composer require deployer/deployer --dev
// deploy.php
namespace Deployer;
require 'recipe/laravel.php';
host('production')
->set('remote_user', 'deploy')
->set('deploy_path', '/var/www/app');
task('deploy', [
'deploy:prepare',
'deploy:vendors',
'artisan:storage:link',
'artisan:config:cache',
'artisan:route:cache',
'artisan:view:cache',
'artisan:migrate',
'deploy:publish',
]);
after('deploy:failed', 'deploy:unlock');
2. Laravelパルスモニタリング
composer require laravel/pulse
php artisan vendor:publish --provider="Laravel\Pulse\PulseServiceProvider"
php artisan migrate
// Dashboard tại /pulse
// Hiển thị: slow queries, exceptions, queue jobs, cache hits
Route::middleware(['auth', 'can:viewPulse'])->group(function () {
Route::get('/pulse', function () {
return view('vendor.pulse.dashboard');
});
});
3.セントリーエラー追跡
composer require sentry/sentry-laravel
php artisan sentry:publish
SENTRY_LARAVEL_DSN=https://[email protected]/0
SENTRY_TRACES_SAMPLE_RATE=0.1
4. 構造化されたロギング
// config/logging.php
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily', 'stderr'],
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'days' => 14,
],
],
// Sử dụng
Log::info('Order placed', ['order_id' => $order->id, 'total' => $order->total]);
5. ヘルスチェック
// routes/web.php
Route::get('/health', function () {
try {
DB::connection()->getPdo();
Cache::store()->get('health-check');
return response()->json(['status' => 'healthy']);
} catch (\Exception $e) {
return response()->json(['status' => 'unhealthy'], 503);
}
});
6. スケーリング戦略
| 戦略 | 説明 |
|---|---|
| オクタン | Swoole/FrankenPHP — アプリをメモリに保持する |
| キューワーカー | 多数のワーカーを水平方向に拡張 |
| リードレプリカ | 独立した読み取り/書き込みデータベース |
| CDN | 静的アセット、メディア ファイル |
| ロードバランサー | Nginx/HAProxy による負荷分散 |
| Redis クラスター | キャッシュとセッションのスケーリング |
シリーズ完結おめでとうございます Laravel: 基本から上級まで! 🎉