Chapter 21. Running PHP on the Command Line

Although PHP was conceived as a tool for creating dynamic web pages, because the PHP language is very powerful, it has also become popular for writing command scripts and even desktop programs.

In this lesson you will learn how to write PHP for use from the command line and create your own command scripts.

The Command-Line Environment

In order to use PHP from the command line, you need to have a PHP executable installed on your system. When running in a web environment, PHP is usually installed as an Apache module, but it is also possible to build a standalone program called php that can be used as a command-line interface (CLI).

Differences Between CLI and CGI Binaries

Beginning in version 4.2, PHP started ...

Get Sams Teach Yourself PHP in 10 Minutes now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.