Symfony框架是否有类似Node.js nodemon的源码变更监听重启工具?
Hey there! I totally get wanting that seamless auto-reload experience like nodemon brings to Node.js—let's break down your options for Symfony:
Symfony 自带的内置解决方案
Great news: Symfony has this functionality built right into its official CLI tool, so you don’t need extra installs for basic use cases.
Just run this command in your project root:
symfony server:start --watch
This fires up the Symfony local server and automatically watches for changes in your project files (PHP scripts, Twig templates, YAML configs, etc.). As soon as you save a change, it’ll restart the server in the background—super straightforward.
第三方工具替代方案
If you want more flexibility (or a tool that works across other PHP projects), here are a couple solid picks:
spatie/php-watcher
This is a popular PHP-specific watcher. First install it as a dev dependency:composer require --dev spatie/php-watcherThen use it to watch your project and trigger a server restart on changes. For example, to monitor core project directories and relevant file types:
./vendor/bin/php-watcher watch --paths src/,templates/,config/ --ext php,twig,yaml --command "symfony server:restart"You can also create a
watcher.ymlconfig file to save your settings, so you don’t have to type the full command every time.Nodemon itself!
You can actually use your familiar nodemon tool with Symfony. If you have it installed globally, run:nodemon --ext php,twig,yaml,json --exec "symfony server:restart"This tells nodemon to watch for changes in those file types, and triggers a server restart every time you save a modification. Perfect if you already know your way around nodemon from Node.js work.
Hope these options help you get that smooth, hassle-free development workflow going!
内容的提问来源于stack exchange,提问作者Pasindu Dilshan

