Hacker News new | past | comments | ask | show | jobs | submit login

Any programmers here who've used PHP to build command line tools in PHP? What is the experience like compared to, let's say Python or node.js? How good are the facilities? What are the limitations?



It's really good. Using the Symfony Console component you get sane argument and option parsing and validation (optional/required, single or array values), output styling, interactive inputs, tables etc.

If you're wanting to build a TUI I haven't seen any libraries as advanced as the Python or JS ones.


Symfony command is great for this https://symfony.com/doc/current/console.html

But it really depends on what you need the command for.

I use Symfony command for general things, Node.js for eg PDF generation, Python for ML, Rust for calculating Ranks/Scores

Development time is the same for all of them.

For whatever reason Node.js scripts always feel dirty to me. I can not even pinpoint why.


I have rewritten more-or-less the same tool, 100KLOC, in Rust and PHP. I can't tell you about Python or Node.js

Use PHP if

- you're in a hurry and you already either know PHP, or the script is going to call other PHP code you've written

- execution speed is not important (ditto for Python and Node)

If neither of the above is true, give Rust a whirl.


I tried to write a CLI tool for orchestration by wrapping some sub-processes. I found PHP very limited in its ability to handle subprocesses (streams, error handling, signal forwarding). I tried to avoid using frameworks, but eventually used Symfony's "Process" lib. It helped with Linux but Windows support is very limited.

This experience was pretty disappointing, but also pretty niche. Overall I agree with the general sentiment that PHP is very nice to use nowadays, especially for web development.


Very easy to do. Check out the getOpt function for argument parsing etc.





Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: