Some Useful PHP Command Line Options

When you use a tool day in, day out, you take a lot of things for granted. Sometimes there are some really useful things available but because you don’t look, you miss them. That got me thinking about php.exe and what some alternative options are available which might be useful. This short article will highlight some of those and give some examples and outputs of their use, where appropriate.

Let’s start with the most obvious.

Help (-h)

The esteemed help page.

Version (-v)

Not sure why your PHP isn’t recognising some new v7 types of code? You need to check the version number.

Modules Loaded (-m)

This shows which modules are loaded with PHP. Very useful if you want to know if XDebug is installed, for example.

Information (-i)

We’ve all done something like this:

but did you know you can do it from the command line? Send the output to a file – it’s going to be big!

The Interactive Shell (-a)

With this, you can try out code snippets or even use it like a calculator!

Type “quit” <return> to exit.

Running Commands on the Command Line (-r)

Similar to the example above, you can run commands on the command line like so:

Watch out for the use of single or double quotes, much like when you use PHP normally.

Viewing Code in Coloured Form (-s)

It’s possible to view your code as colourized HTML. Really! Switch the path to your favourite browser with the command below.

Removing Whitespace and Comments (-w)

This is a quite useful option which will remove all comments and blank lines from your source code. So, given this small script:

You end up with this:

Let’s finish with one more.

Setting Defined Constants

This example is straight from the manual and is a good demonstration:

Hopefully that showed you something you haven’t seen before. Of course, check out the command line help or the manual link above for even more examples such as timing routines, checking syntax and starting in-built servers etc.


Written by Stephen Moon
email: stephen at

Hey! Did you enjoy reading this? If you did and would like an email when I add new content, just subscribe to my list. You can unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *