How do I register code to be called at a specific time in the future?
I want to allow users to create “objects” and have a handler that automatically emails them statistics about that object after a given amount of time (say 1 hour). Ideally, I could register a handler with some part of the Symfony codebase, but I can’t find out how to do this (all googling so far is stuff about the timing of Symfony2’s beta :P)
I’d recommend you create a Symfony2 console command, as then you get access to the whole framework including the dependency injection container and so on. The specifics of this are over in the Symfony2 cookbook, so I won’t duplicate them here as the cookbook entry is pretty thorough. Once you’ve created your command class with a task name of eg
example:my-task, you can then pop an entry in your crontab file similar to the following:appending any command-line arguments as appropriate eg
--env=prod. The path above is the path to wherever your Symfony2 application is and subsequently being able to run the Symfony2app/consolescript.