Dominic Fagan Dominic Fagan - 1 year ago 109
PHP Question

How to run PHP script, whs in Windows CLI

I used linux for years but I got a new laptop and haven't bothered to install linux on it yet, instead I've been getting to know Windows better. cmd.exe is absolutely horrific, its so bad I regularly feel like switching back to linux. I can't use it at all. I use PowerShell instead but even thats pretty bad.

With the linux CLIs like bash, when I run a PHP script with a loop, and echo something inside the loop, it will output what I echoed onto the screen with each iteration. PowerShell doesn't do this, it just displays nothing until the script has finished running. I run a lot of web scrapers so this is a big problem for me.

Is there a PHP CLI that I can download that will work better than PowerShell? I also came across an amazing IDE called PHPStorm today, I think it might possibly let you run PHP scripts inside a built in CLI but I haven't figured it out yet. It has a built in web server, but it also lets you add your own web server, and lets you interact with MySQL databases and other impressive things like that.

Answer Source

You can run PHP scripts from the commandline in Windows as well. Given you have a file namned main.php you can run this file by just writing php %filename% (So php main.php) in this case. Anything written to the standard output stream will appear in the console.

The php binary is not present in the environment path variable by default and should be added.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download