blog

How to Run Cron Jobs in Symfony

Share:

If you’ve ever needed to run scheduled tasks in a Symfony app—like sending emails every hour, syncing data, or cleaning up logs—you’ve probably asked:

“What’s the best way to handle cron jobs in Symfony?”

Let’s break it down step by step—with real code and zero fluff.

🔧 What’s cron/cron-bundle?

It’s a Symfony bundle that lets you define and manage cron jobs inside your app, using Symfony console commands. You schedule jobs via cron expressions and let the bundle handle execution, logging, and more.

Think: Laravel scheduler vibes, Symfony style.

🚀 Step 1: Install the Bundle

Start by installing it via Composer:

composer require cron/cron-bundle

If you’re not using Symfony Flex, manually enable it in config/bundles.php:

✍️ Step 2: Create Your Symfony Command

Let’s say we want to send a summary email every hour. Create the command:

php bin/console make:command App\\Command\\SendSummaryEmailCommand

Update the generated file:

🗄️ Step 3: Create the Cron Job Table

The bundle provides a default cron_job table. No need to build a custom entity.

Run the migration:

Done! You’re ready to add jobs.

🧩 Step 4: Add Jobs to the Database

Add new jobs by inserting rows into the cron_job table. Key fields:

  • name: A friendly label (e.g. “Send Summary Email”)
  • command: The Symfony command to run (e.g. app:send-summary-email)
  • schedule: Standard cron expression (e.g. 0 * * * *)
  • enabled: Set to 1 to activate it

This gives you full control from the DB—no config files or code changes required.

🏃 Step 5: Run Scheduled Jobs

To execute due jobs, run:

The bundle will check the schedule and run any jobs that are due.

🔁 Automate with System Cron

To run jobs automatically, set up a system cron to trigger every minute:

Now your Symfony app is running scheduled tasks like a champ.

📝 Want to track job output?
  • Pipe the system cron output to a log file
  • Add Symfony logger calls inside your commands
  • Store job results or statuses in a custom table for auditing

You’ve got options.

✅ Recap

With cron/cron-bundle, scheduled tasks in Symfony become:

  • Dynamic – controlled via the database
  • Flexible – update jobs without touching code
  • Clean – no YAML or messy configs
  • Powerful – supports any Symfony command

You can even build an internal UI to manage jobs from your admin panel.

That’s it—cron jobs in Symfony, simplified.

Happy coding🎯

Related articles

Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon
Circle icon

get in touch

EVEN IF YOU DON'T YET KNOW WHERE TO START WITH YOUR PROJECT - THIS IS THE PLACE

Drop us a few lines and we'll get back to you within one business day.

Thank you for your inquiry! Someone from our team will contact you shortly.
Where from have you heard about us?
Clutch
GoodFirms
Crunchbase
Googlesearch
LinkedIn
Facebook
Your option
I have read and accepted the Terms & Conditions and Privacy Policy
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
slash icon
slash icon
slash icon
slash icon
slash icon
slash icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon
bracket icon