Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 execute script from cron job

Tags:

cron

symfony

I need to create a script to periodically send emails to some users. I have thought in creating a function in the controller and a path in the routing and in the cron job call www.mydomain.com/send for example.

But i don't think that is the best way to do it because whatever user could call the script.. What is the correct way to do so?

class UserController extends Controller{

    public function sendAction(){
            $em = $this->getDoctrine()->getEntityManager();
            ...
    }
}
like image 467
nasy Avatar asked Dec 08 '22 21:12

nasy


1 Answers

Your feeling is right, using Controller actions is not the best way to solve your task.

There's a much better way - Console Commands. It's much safer (no risk that somebody from outside calls it) and faster (much faster to load).

like image 87
Inoryy Avatar answered Dec 18 '22 00:12

Inoryy