0

I would create a background task that loops continuously with Symfony2

I want to know how to do this

protected function execute(){
   while (true) {
      sleep(60);
      //------------ do some think
}}
ghaziksibi
  • 461
  • 2
  • 12

1 Answers1

0

As far as I know, PHP doesn't have threading, so you won't be able to run that in parallel with your Symfony application.

Instead, create a cron job which executes that code via CLI.

Here's a pretty straight-forward intro to cron jobs.

If you're on a Windows server, set up a scheduled task. See How to run a PHP file in a scheduled task (Windows Task Scheduler).

Community
  • 1
  • 1
Alec
  • 1,539
  • 4
  • 15
  • 37