Search code examples
symfonyconsolecroncommandcron-task

How can i open and write in cron file task using symfony2


I'm creating an application in Symfony2.4. I also have the command, I want to add the command in cron a task using symfony2, not manually namely, the via symfony2, open and write. Any suggestions to get this done.


Solution

  • faost thanks. but I know how to add in cron manually via the console, I was interested how it do through the controller. In short, I found the solution :)


    $output = shell_exec('crontab -l');
    file_put_contents('/crontab.txt', $output.'* * * * * command'.PHP_EOL, FILE_APPEND | LOCK_EX);
    echo exec('crontab /crontab.txt');