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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.