@DaleZ @luceos"#1376 This is the way I inally fixed the 10–15 second delay when posting! (Queue + Cron setup). Right now, users can post almost instantly:
---
The problem:
Every time I posted something, the page would just hang there forever. Turns out, as Luceos suggested, Flarum was trying to send email notifications to all followers in real-time, and since I'm using Gmail SMTP (which is pretty slow), it was blocking the whole process. The more followers a discussion had, the longer it took.
What I did (step by step):
1. Changed the queue driver in config.php
I opened my config.php file and added this:
'queue' => [
'driver' => 'database',
],
This tells Flarum to use the database for queuing tasks instead of processing everything immediately.
2. Installed the Database Queue extension
I ran this command via SSH:
composer require blomstra/database-queue:"*"
Then activated the extension in the admin panel and ran:
php flarum migrate
This created the necessary queue_jobs and queue_failed_jobs tables in my database.
3. Set up the Cron Job (this was the tricky part)
I'm on Hostinger shared hosting, so I had to figure out their cron job system. Here's what worked for me:
First, I created a small script file called cron-flarum.sh inside my Flarum root folder (where config.php is):
#!/bin/sh
cd /home/YOUR_USERNAME/domains/YOUR_DOMAIN.com/public_html && /usr/bin/php flarum schedule:run > /dev/null 2>&1
(Replace YOUR_USERNAME and YOUR_DOMAIN with your actual details!)
Then I gave it execution permissions:
chmod +x cron-flarum.sh
In the Hostinger panel (hPanel), I went to Cron Jobs and created a new task:
- Type: Custom
- Command to run:
/bin/sh /home/YOUR_USERNAME/domains/YOUR_DOMAIN.com/public_html/cron-flarum.sh
- Schedule: Every minute (
* * * * *)
Important: If you try to run the command directly with && or > symbols in Hostinger's cron panel, it might fail. That's why I used the .sh script approach – it's cleaner and more reliable on shared hosting.
4. Cleared the cache
php flarum cache:clear
The result:
Now when I check the admin panel, I see:
- Scheduler: Active ✅
- Queue Driver: database ✅
- Queue Overview: Running ✅
And the best part: posting is now almost instant! It takes less than 2 seconds. The emails get sent in the background by the cron job, so users don't have to wait anymore.
One thing to watch out for:
Environment:
- Flarum 1.8.11
- PHP 8.2.30
- MySQL 11.8.8-MariaDB
- Hostinger shared hosting
Hope this helps someone! – I spent way too much time figuring this out, so happy to save others the headache. 😅
And thanks to you bc I addressed this situation thanks to your post. And thanks to Luceos too, he did in fact pointed this out correctly.
And blomstra/database-queue , what a great extension. Thank you! 😀
Deepseek IA helped me all the way out!