Symfony2 runs script from cron job

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

But I do not think this is the best way to do this, because any user can call the script. What is the right way to do this?

class UserController extends Controller{ public function sendAction(){ $em = $this->getDoctrine()->getEntityManager(); ... } } 
+4
source share
1 answer

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

Here is a much better way - Console Commands . This is much safer (without the risk that someone calls him from outside) and faster (much faster to load).

+14
source

Source: https://habr.com/ru/post/1433862/


All Articles