Command line PHP

I’ve discovered two things about command line PHP today.  I’ll share them here just in case you missed them too.

First, the “-f” parameter is optional.  I’m not sure when the change happened, but I’m pretty sure back when I started using it, it was required.  Now, instead of “php -f some.php” you can run just “php some.php”.

Second, there is now an interactive PHP mode! This is something I wanted for years.  Prior to PHP I had experience with Perl and Python, both of which have interactive modes.  With PHP I had to resort to a gadzillion of tiny files with snippets of code.  Now I don’t have to anymore.  Just run “php -a” and type away.

Have a look at PHP command line options manual page.  Maybe you’ll discover something else.

4 thoughts on “Command line PHP”


  1. I am using opensuse 12.1. How did you get it to work? When I do the same thing, it does not actually execute my code until I ctrl+d and then everything is executed all at once rather than line by line, as a truly interactive cli. Must I reinstall php with some non-default compile options?


  2. For Years I used Fedora. I switched after I could no longer find repositories for fedora 8. That was my favourite OS. I may need to go back. There is supposed to be a record somewhere of the command used to install php with properly working command line. I cannot remember where it is now.

    Thank you, though.


    1. The installation on RedHat-based distributions is simple – with “rpm -ivh some.rpm” or with “yum install some-package”. But RPM packages are pre-compiled. What you are probably after is the way PHP was compiled in those packages. To find that out, you need to get a Source RPM, install it, and examine the .spec file (which is an RPM analogue of Makefile).

Leave a Comment