symfony2在正式环境下配置立即生效需清除缓存

Since the prod environment is optimized for speed; the configuration,routing and Twig templates are compiled into flat PHP classes and cached.When viewing changes in the prod environment, you’ll need to clear thesecached files and allow them to rebuild:

php app/console cache:clear --env=prod --no-debug
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Symfony4 中,你可以使用定时任务组件Symfony\Component\Console\Command\Scheduler来安排定时任务。以下是配置步骤: 1. 安装组件: ``` composer require symfony/console ``` 2. 创建定时任务类,如下所示: ``` namespace App\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class MyScheduledTaskCommand extends Command { protected static $defaultName = 'my:scheduled:task'; protected function configure() { $this ->setDescription('My scheduled task'); } protected function execute(InputInterface $input, OutputInterface $output) { // Do something here } } ``` 3. 创建定时任务定义类,如下所示: ``` namespace App\Console; use App\Command\MyScheduledTaskCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\SchedulerRuntimeException; use Symfony\Component\Console\Scheduler\Schedule; use Symfony\Component\Console\Scheduler\ScheduleBuilder; use Symfony\Component\Console\Scheduler\SymfonyScheduler; class Scheduler { private $scheduler; public function __construct() { $this->scheduler = new SymfonyScheduler(); } public function schedule(): void { $this->scheduler->addCommand(new MyScheduledTaskCommand()) ->setDescription('My scheduled task') ->setSchedule((new ScheduleBuilder()) ->at('*/5 * * * *') ->getSchedule() ); } public function run(): void { try { $this->scheduler->run(); } catch (SchedulerRuntimeException $e) { // Handle exception here } } } ``` 4. 在services.yaml文件中定义Scheduler服务: ``` services: _defaults: autowire: true autoconfigure: true public: false App\Console\Scheduler: public: true ``` 5. 在控制器或其他地方调用Scheduler服务的schedule()方法,如下所示: ``` namespace App\Controller; use App\Console\Scheduler; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; class DefaultController extends AbstractController { /** * @Route("/schedule") */ public function schedule(Scheduler $scheduler) { $scheduler->schedule(); return $this->redirectToRoute('homepage'); } } ``` 6. 在终端中运行以下命令,以启动定时任务: ``` php bin/console schedule:run ``` 以上就是在Symfony4中配置定时任务的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值