Help more people learn by sharing this post!

PHP: Top command-line options

Here are some useful php command line options that you will love. Ever wanted to test a quick snippet of code without having to save it to a file and then run it? Well check this out! If you invoke php with the -a flag it will drop you into an interactive session. This is nothing more than a REPL (Read, Eval, Print, Loop) that let’s you type any php code and execute it immediately. It also helps you with tab-completion of variable names and functions.

php command line

You could even use include to load a php file and test functions in isolation, so this is useful in case you don’t have unit test and want to make sure that a function is doing what it’s supposed to or if this function would usually be triggered by something like an ajax call but you don’t have that available yet.

If you are using a text editor instead of a full blown php IDE you will like the next option: php -l will perfom a syntax check on your code without actually running it.

php command line

Another useful one is php –ini which will show you what configuration files are being loaded by php (for the CLI version), this information is also available via the phpinfo() function.

php-ini

And finally another option you may find useful is: php -S localhost:80 which spins up a dev web server. This is similar to the python version python -m SimpleHTTPServer

Make sure you try those out and let me know in the comments if you know any other cool php tricks :)

Related posts:
http://www.blackbytes.info/2012/09/php-arrays/