Laravel Horizon Sinhala Guide
Laravel Horizon ගැන සම්පූර්ණ මාර්ගෝපදේශයක් (Laravel Horizon Sinhala Guide)
Laravel framework භාවිතා කරන developer කෙනෙකු නම් Laravel Horizon යනු Queue system එක professional ලෙස manage කිරීම සඳහා භාවිතා කරන ඉතා වැදගත් tool එකකි.
මෙම ලිපිය තුළ Laravel Horizon පිළිබඳ සම්පූර්ණ විස්තරයක් Sinhala භාෂාවෙන්, පැහැදිලි සහ වඩාත් පහසු ලෙස ඉදිරිපත් කර ඇත.
Laravel Horizon කියන්නේ මොනවද?
Laravel Horizon යනු Laravel Queue system එක (Redis මත පදනම් වූ) තුළ ක්රියාත්මක වන jobs නිරීක්ෂණය කර පාලනය කිරීම සහ විශ්ලේෂණය කිරීම සඳහා Laravel විසින් නිල වශයෙන් ලබා දෙන package එකකි.
Laravel Horizon භාවිතා කිරීමෙන් ඔබට:
- Queue jobs real-time ලෙස නිරීක්ෂණය කිරීම
- අසාර්ථක වූ jobs (failed jobs) හඳුනාගැනීම
- Worker වල කාර්ය සාධනය (performance) මැනීම
- Queue throughput පිළිබඳ විශ්ලේෂණය කිරීම
වැනි කාර්යයන් පහසුවෙන් සිදු කළ හැක.
Laravel Horizon භාවිතා කළ යුතු හේතු
Laravel Horizon Laravel developers අතර ඉතා ජනප්රිය වීමට හේතු වන ප්රධාන කරුණු කිහිපයක් පහත පරිදි වේ:
- Real-time ලෙස Queue තත්ත්වය පෙන්වන dashboard එක
- Queue system එකේ ඉහළ කාර්ය සාධනය (high performance monitoring)
- Failed jobs පහසුවෙන් හඳුනාගත හැකි වීම
- පිරිසිදු හා භාවිතයට පහසු user interface එක
- Production environment සඳහා සූදානම් queue management system එක
Laravel Horizon Installation (ස්ථාපනය)
Laravel Horizon install කිරීම සඳහා පහත command භාවිතා කරන්න:
composer require laravel/horizon
Configuration files publish කිරීමට:
php artisan horizon:install
⚠️ සැලකිලිමත් වන්න:
Queue driver එක redis ලෙස set කර ඇති බව සහ Redis server එක correctly configure කර ඇති බව තහවුරු කරගන්න.
Laravel Horizon Dashboard
Laravel Horizon install කිරීමෙන් පසු dashboard එක access කළ හැක්කේ:
Dashboard එක තුළ ඔබට:
- Recent Jobs
- Failed Jobs
- Job Runtime
- Queue Throughput
- Worker Status
වැනි විස්තර graphical ලෙස නිරීක්ෂණය කළ හැක.
Laravel Horizon සහ Redis
Laravel Horizon සම්පූර්ණයෙන්ම Redis මත පදනම්ව ක්රියා කරයි.
Redis high-speed in-memory data store එකක් වන නිසා Laravel Horizon:
- ඉතා වේගවත් වේ
- Large-scale queue systems handle කරයි
- Production environments සඳහා සුදුසු වේ
Production Environment එකේ Horizon run කිරීම
Production server එකක Laravel Horizon run කිරීම සඳහා:
php artisan horizon
හොඳම practice එකක් වන්නේ Supervisor භාවිතා කර Horizon background process එකක් ලෙස run කිරීමයි.
Laravel Horizon Security
Production environment එකේදී Horizon dashboard එක public access නොවීමට restrict කළ යුතුයි.
Laravel Horizon authorization control සඳහා:
Horizon::auth()method භාවිතා කර- Admin users සඳහා පමණක් access ලබා දිය හැක
මෙය application security සඳහා ඉතා වැදගත් වේ.
Laravel Horizon සඳහා ප්රධාන Search Terms
- Laravel Horizon Sinhala
- Laravel Horizon ගැන මාර්ගෝපදේශය (Laravel Horizon Tutorial)
- Laravel Queue monitoring
- Redis භාවිතා කරන Laravel Queue
- Laravel Horizon dashboard
Laravel Horizon භාවිතා කළ යුතු අවස්ථා
Laravel Horizon භාවිතා කිරීම වඩාත් සුදුසු වන්නේ පහත වගේ අවස්ථාවලදීය:
- විශාල පරිමාණයේ Laravel application තිබෙන විට
- එකම වේලාවක බොහෝ පරිශීලකයන් (high traffic) system එක භාවිතා කරන විට
- background jobs වැඩි ප්රමාණයක් ක්රියාත්මක වන systems සඳහා
- online වෙළඳසැල් (E-commerce systems) සඳහා
- API මත පදනම් වූ systems සඳහා
Laravel Horizon ස්ථාපනය කිරීම (Installation)
Laravel Horizon භාවිතා කිරීමට පෙර ඔබගේ Laravel project එක Redis සමඟ configure කර ඇති බවට සහතික විය යුතුය. Horizon වෙත queues power කිරීම Redis මත පදනම් වෙයි. මේ සඳහා, ඔබගේ config/queue.php configuration file එකේ queue connection එක redis ලෙස සකස් කර ඇති බවට පරීක්ෂා කරන්න.
දැනට, Horizon Redis Cluster සමඟ compatible නොවේ.
Horizon ස්ථාපනය කිරීම
ඔබට Horizon package එක Composer භාවිතා කර project එකට install කළ හැක:
composer require laravel/horizon
ස්ථාපනයෙන් පසුව, Horizon assets publish කිරීම සඳහා පහත command එක භාවිතා කරන්න:
php artisan horizon:install
මෙම command එකෙන් ඔබගේ project එකේ Horizon assets සහ configuration files create වේ.

Laravel Horizon වින්යාසය (Configuration)
Horizon assets publish කිරීමෙන් පසුව, primary configuration file එක config/horizon.php තුළ සොයා ගත හැක. මෙම file එක ඔබගේ queue worker options define කිරීමට සහ environment-specific settings set කිරීමට භාවිතා වේ.
Key Points:
- Horizon uses a Redis connection named
horizoninternally. මෙම connection name වෙනත් Redis connection එකක් සඳහා භාවිතා නොකළ යුතුය. environmentsoption එක තුළ, production සහ local environment සඳහා default worker process configurations define වේ. ඔබට අවශ්යනම් extra environments එකතු කළ හැක.
Environments Example
'environments' => [
'production' => [
'supervisor-1' => [
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
],
],
'local' => [
'supervisor-1' => [
'maxProcesses' => 3,
],
],
],
ඔබට wildcard environment (*) define කළ හැක, මෙය කිසිඳු specific environment එකකට match නොවු විට භාවිතා වේ:
'environments' => [
'*' => [
'supervisor-1' => [
'maxProcesses' => 3,
],
],
],
Supervisors
- Supervisor යනු worker process එකක් supervise කරන component එකකි.
- ඔබට අවශ්ය නම්, එක environment එකේ multiple supervisors define කළ හැක.
- Each supervisor manages a group of workers, balancing queue load dynamically.
Maintenance Mode
Application එක maintenance mode එකේ තිබේ නම්, queued jobs process නොවේ unless force option එක true ලෙස define කර ඇත:
'environments' => [
'production' => [
'supervisor-1' => [
'force' => true,
],
],
],
Default Values
- Horizon configuration file එකේ defaults option එක, supervisors සඳහා default values define කරයි.
- මෙය repetition අඩු කරයි සහ supervisor configuration streamline කරයි.
Dashboard Authorization
- Horizon dashboard /horizon route එකේ access කළ හැක.
- Non-local environments වල access control HorizonServiceProvider.php file එකේ authorization gate එකෙන් manage වේ:
Laravel Horizon Balancing Strategies (වැලි සමාන කිරීමේ තාක්ෂණ)
Horizon supervisors තුළ worker processes queues අතර load dynamically distribute කරයි. ඔබට තේරීමට අවශ්ය three balancing strategies ඇත: auto, simple, සහ false.
1. Auto Balancing
- Default strategy එක
auto. - Worker processes dynamically allocate කරයි queue workload අනුව.
- Auto scaling options:
minProcesses,maxProcesses,balanceMaxShift,balanceCooldown.
'environments' => [
'production' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['default', 'notifications'],
'balance' => 'auto',
'minProcesses' => 1,
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
],
],
],
Tip: Auto strategy time or size based scaling use කරයි.
time→ queues clear කිරීමේ estimated time අනුව workers assign කරයි.size→ queue length අනුව workers assign කරයි.
2. Simple Balancing
- Workers fixed number queues අතර evenly distribute කරයි.
- Scaling automatic නොවේ.
'environments' => [
'production' => [
'supervisor-1' => [
'queue' => ['default', 'notifications'],
'balance' => 'simple',
'processes' => 10,
],
],
],
Tip: Queue-specific process control අවශ්ය නම් multiple supervisors define කළ හැක.
3. No Balancing
- Queues strict order එකේ process කරයි.
- Worker processes still scale according to
minProcesses/maxProcesses.
'environments' => [
'production' => [
'supervisor-1' => [
'queue' => ['default', 'notifications'],
'balance' => false,
'minProcesses' => 1,
'maxProcesses' => 10,
],
],
],
Laravel Horizon Job Handling (කාර්ය පාලනය)
Horizon supervisors jobs manage කිරීමේදී Max Attempts, Timeout, Backoff සහ Silenced Jobs support කරයි.
1. Max Job Attempts
triesoption එක supervisor level එකේ set කළ හැක.- Job class එකේ
$triesproperty override කරයි supervisor config.
'environments' => [
'production' => [
'supervisor-1' => [
'tries' => 10,
],
],
],
tries = 0→ unlimited attempts.$maxExceptionsdefine කර failed jobs avoid කිරීමේදී use වේ.

2. Job Timeout
- Worker එකක් job එක process කරන maximum seconds set කරයි.
'environments' => [
'production' => [
'supervisor-1' => [
'timeout' => 60,
],
],
],
Tip: Horizon timeout > job-level timeout, queue retry_after value ≤ timeout.
3. Job Backoff
- Job retry delay define කරයි unhandled exception encounters වෙලාවට.
'environments' => [
'production' => [
'supervisor-1' => [
'backoff' => 10,
],
],
],
- Exponential backoff use කළ හැක:
'backoff' => [1, 5, 10],
- Retry delay: 1s, 5s, 10s, then 10s for subsequent attempts.
4. Silenced Jobs
- Certain jobs hide කිරීමට
silencedoption use කරයි.
'silenced' => [
App\Jobs\ProcessPodcast::class,
],
- Tags based silencing:
'silenced_tags' => [
'notifications',
],
- Job class implement කර Laravel\Horizon\Contracts\Silenced interface automatically silence කරයි:
use Laravel\Horizon\Contracts\Silenced;
class ProcessPodcast implements ShouldQueue, Silenced
{
use Queueable;
// ...
}
Tip: Silenced jobs dashboard clutter අවම කරයි and monitoring focus improve කරයි.
Laravel Horizon Notifications (සටහන් ඇතුළත් කිරීම)
Horizon, queued jobs සඳහා Slack, SMS, Mail notifications support කරයි. මෙය ඔබට queues long wait time හෝ failed jobs පිළිබඳ real-time alerts ලබා ගන්න උපකාරී වේ.
Notification Configuration
- Notifications define කිරීමට
Horizon::routeMailNotificationsTo,Horizon::routeSlackNotificationsTo, සහHorizon::routeSmsNotificationsTomethods use කරයි. - Methods call කිරීම App\Providers\HorizonServiceProvider class එකේ
boot()method එකේ සිදු කළ යුතුය.
'boot' => [
Horizon::routeSmsNotificationsTo('15556667777'),
Horizon::routeMailNotificationsTo('example@example.com'),
Horizon::routeSlackNotificationsTo('slack-webhook-url', '#channel'),
],
Wait Time Thresholds
waitsoption එක long wait time thresholds define කරයි queues/connection combination එකකට.
'waits' => [
'redis:critical' => 30,
'redis:default' => 60,
'redis:batch' => 120,
],
- 0 value set කිරීම → long wait notifications disable වේ.

Laravel Horizon Metrics & Clearing Jobs (මානක සහ Job Clear කිරීම)
Horizon metrics dashboard එක job wait times, throughput, and performance display කරයි. Metrics update කිරීම සඳහා snapshot command schedule කල යුතුය.
Metrics
- Horizon snapshot command schedule කිරීම:
Schedule::command('horizon:snapshot')->everyFiveMinutes(),
- Metrics clear කිරීමට:
horizon:clear-metrics
Clearing Failed Jobs
- Single failed job remove කිරීමට:
horizon:forget 5
- All failed jobs remove කිරීමට:
horizon:forget --all
Clearing Jobs From Queues
- Default queue එකේ සියලු jobs remove කිරීමට:
horizon:clear
- Specific queue එකේ jobs remove කිරීමට:
horizon:clear --queue=emails
Tip: Regular metrics check කිරීම, long wait alerts setup කිරීම සහ failed jobs clear කිරීම production environment එකේ queue reliability improve කරයි.
සාරාංශය
Laravel Horizon යනු Laravel Queue system එක නිසි ලෙස නිරීක්ෂණය (monitoring) කර පාලනය (management) කිරීම සඳහා භාවිතා කරන අත්යවශ්ය tool එකකි.
Real-time ලෙස jobs බලන්න පුළුවන් වීම, භාවිතයට පහසු dashboard එක සහ Redis මත පදනම් වූ වේගවත් ක්රියාකාරීත්වය නිසා Laravel Horizon Laravel developer කෙනෙකුට ඉතා වැදගත් package එකක් බවට පත්වේ.
ඔබගේ Laravel application එක production මට්ටමට ගෙන යාමට ඔබ අදහස් කරන්නේ නම්, Laravel Horizon ඔබට විශ්වාසයෙන් භාවිතා කළ හැකි හොඳම විසඳුමක් වේ.
✨ Laravel Horizon සමඟ සාර්ථක coding එකක් කරමු!