PHP code example of fof / horizon
1. Go to this page and download the library: Download fof/horizon 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/ */
fof / horizon example snippets
use FoF\Redis\Extend\Redis;
return [
// Basic Redis configuration
new Redis([
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
'database' => 0,
]),
// ... other extenders
];
return [
(new Redis([
'host' => '127.0.0.1',
'password' => null,
'port' => 6379,
]))
->useDatabaseWith('cache', 1)
->useDatabaseWith('queue', 2)
->useDatabaseWith('session', 3),
];
return [
(new Redis([
'host' => '127.0.0.1',
'port' => 6379,
]))
->disable(['cache']), // Only use Redis for queue and sessions
];
return [
new Redis([
'host' => '127.0.0.1',
'port' => 26379,
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
],
]),
];
return [
'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default'],
'balance' => 'auto',
'autoScalingStrategy' => 'time',
'maxProcesses' => 10,
'maxTime' => 0,
'maxJobs' => 0,
'memory' => 128,
'tries' => 3,
'timeout' => 60,
'nice' => 0,
],
],
'environments' => [
'production' => [
'supervisor-1' => [
'maxProcesses' => 20,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
],
],
],
];
use FoF\Horizon\Extend\Horizon;
return [
(new Horizon)->config('./config/horizon.php'),
];
'horizon' => [
'memory_limit' => 256, // MB — master supervisor
],
(new \FoF\Horizon\Extend\Horizon)->config([
'memory_limit' => 256, // MB — master supervisor
'environments' => [
'production' => [
'supervisor-1' => [
'memory' => 256, // MB — per worker
],
],
],
]),
'defaults' => [
'supervisor-1' => [
'maxJobs' => 1000, // Restart after X jobs
'maxTime' => 3600, // Restart after X seconds
],
],
bash
composer ache:clear
bash
php flarum horizon
ini
[Unit]
Description=Flarum Horizon
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/flarum
ExecStart=/usr/bin/php /var/www/flarum/flarum horizon
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
bash
php flarum horizon
bash
php flarum horizon:list
bash
php flarum horizon:pause
bash
php flarum horizon:continue
bash
php flarum horizon:pause-supervisor supervisor-1
bash
php flarum horizon:continue-supervisor supervisor-1
bash
php flarum horizon:status
bash
php flarum horizon:supervisor-status supervisor-1
bash
php flarum horizon:terminate
bash
php flarum horizon:clear redis --queue=default
bash
php flarum horizon:purge
bash
php flarum horizon:forget {job-id}
bash
php flarum horizon:clear-metrics
bash
php flarum horizon:terminate
# Wait a few seconds for graceful shutdown
php flarum horizon
bash
composer update fof/horizon
php flarum migrate
php flarum cache:clear
php flarum horizon:terminate