PHP Command Line Interface
PHP CLI Tutorial
This tutorial is intended for anybody who wants to write PHP Scripts that don't require a web server (neither Apache Web Server nor Microsoft IIS). PHP CLI can be used for a wide range of things
. After you read this tutorial, you able to write your own PHP CLI scripts.
There are two ways you can execute your PHP CLI scripts:
- The first way is to use php -f /path/to/yourfile.php. This calls the PHP binary and passes your script as a parameter. This is ugly and ineffective.
- The preferred manner is to chmod +x PHP files that you wish to call from a command line and add an appropriate shebang line at the top of your PHP script ( #!/usr/local/bin/php - make sure that you supply here correct path to your PHP binary).