PHP code example of smwks / laravel-zenith
1. Go to this page and download the library: Download smwks/laravel-zenith 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/ */
smwks / laravel-zenith example snippets
Schedule::command('zenith:monitor')->everyMinute();
// config/zenith.php
return [
// Master switch — disable to stop all monitoring without removing the package
'enabled' => env('ZENITH_ENABLED', true),
'route' => [
'domain' => env('ZENITH_ROUTE_DOMAIN', null), // restrict dashboard to a specific domain
'prefix' => env('ZENITH_ROUTE_PREFIX', 'zenith'),
'middleware' => ['web', 'auth'],
],
// Named supervisor groups — each `zenith:work --name=X` invocation reads from its group
'supervisors' => [
'default' => [
'connection' => env('QUEUE_CONNECTION', 'database'),
'queue' => 'default',
'balance' => env('ZENITH_BALANCE', 'fixed'), // fixed | manual | automatic
'min_workers' => env('ZENITH_MIN_WORKERS', 1),
'max_workers' => env('ZENITH_MAX_WORKERS', 1),
'jobs_per_worker' => env('ZENITH_JOBS_PER_WORKER', 5), // automatic balance only
],
],
// How often workers report their heartbeat (seconds)
'heartbeat_interval' => env('ZENITH_HEARTBEAT_INTERVAL', 30),
// How long without a heartbeat before a worker is considered stuck (seconds)
'stuck_job_threshold' => env('ZENITH_STUCK_JOB_THRESHOLD', 120),
// Automatically release stuck jobs back to the queue
'auto_retry_stuck_jobs' => env('ZENITH_AUTO_RETRY_STUCK_JOBS', false),
'retention' => [
'completed_jobs' => env('ZENITH_RETAIN_COMPLETED_JOBS', 7),
'failed_jobs' => env('ZENITH_RETAIN_FAILED_JOBS', 30),
'job_events' => env('ZENITH_RETAIN_JOB_EVENTS', 7),
],
// Override the database connection used by Zenith tables
'database_connection' => env('ZENITH_DB_CONNECTION', null),
];
'supervisors' => [
'default' => [
'queue' => 'default',
'balance' => 'fixed',
'min_workers' => 2,
'max_workers' => 2,
],
'high-priority' => [
'queue' => 'high,default',
'balance' => 'automatic',
'min_workers' => 1,
'max_workers' => 8,
'jobs_per_worker' => 10,
],
],
// routes/console.php
use Illuminate\Support\Facades\Schedule;
Schedule::command('zenith:monitor')->everyMinute();
Schedule::command('zenith:prune --all')->daily();
bash
composer vendor:publish --tag="zenith-migrations"
php artisan migrate
bash
php artisan zenith:work --queue=default
bash
php artisan vendor:publish --tag="zenith-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="zenith-config"
bash
php artisan vendor:publish --tag="zenith-views"
bash
php artisan zenith:work --queue=default --name=my-worker
bash
php artisan zenith:monitor
php artisan zenith:monitor --auto-retry
bash
php artisan zenith:prune
php artisan zenith:prune --completed=7 --failed=30 --events=7
bash
php artisan zenith:work --name=default
php artisan zenith:work --name=high-priority