PHP code example of cboxdk / laravel-queue-metrics
1. Go to this page and download the library: Download cboxdk/laravel-queue-metrics library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cboxdk / laravel-queue-metrics example snippets
use Cbox\LaravelQueueMetrics\Facades\QueueMetrics;
// Get job performance metrics
$metrics = QueueMetrics::getJobMetrics(ProcessOrder::class);
echo "Processed: {$metrics->totalProcessed}\n";
echo "P95 Duration: {$metrics->duration->p95}ms\n";
echo "Failure Rate: {$metrics->failureRate}%\n";
echo "Health Score: {$metrics->health->score}/100\n";
// React to events
Event::listen(HealthScoreChanged::class, function ($event) {
if ($event->toStatus === 'critical') {
Slack::alert("Queue health critical!");
}
});
// config/queue-metrics.php
'api' => [
'enabled' => true,
'middleware' => ['api', 'auth:sanctum'], // Secure the API
],