I want to develop an interactive command based php application, so I did some research and bumped into the Symfony\Console component. This is great, because it lets met run
php script.php command --option
However, the script then runs the command and closes, and I want to be able to run another command. So basically, something like
php script.php
Which then listens on php://stdin for commands, structured as
command --option
then runs the command and starts listening for new commands. When a specific "exit" command is run, the script should terminate.
I'm relatively new to Symfony and the Console component, so any thoughts on how to implement this, using Symfony\Console? Because I really like the way how Symfony\Console abstracts all the command-stuff away.
Well, you have to enclose your script.php in a cycle like that:
while true {
<reading stdin>
<executing command via Symfony2 component>
}
You will be able to terminate the cycle by pressing Ctrl-C
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With