With the introduction of version 4.2, PHP has started supporting a new SAPI (Server Application Programming Interface) called CLI (Command Line Interface). This facility was introduced to help developers create small shell applications (scripts) with PHP. So, now you can kiss Perl goodbye forever.
The CLI SAPI was released for the first time with PHP 4.2.0, but was still experimental back then and had to be explicitly enabled with --enable-cli when running ./configure. With PHP 4.3.0 the CLI SAPI will no longer be experimental and therefore will always be built and installed as the php (called php.exe on Windows) binary.
What is PHP Shell Scripts?
Normally shells are interactive, but not always. It means the shell will accept commands from you through keyboard and execute them. But instead of issuing commands one by one we can store this sequence of commands into a text file and tell the PHP to execute this text file instead of entering the commands. This is known as PHP shell scripting.
A PHP Shell script is just like batch file is MS-DOS but has more power than the MS-DOS batch file, thanks to PHP.
Why Write Shell Scripts?
Shell scripts can take input from a user or a file and output them to the screen.
Useful to create our own commands/application.
Don't have to reinvent the wheel.
To automate some day to day tasks.
In this tutorial we shall learn how to use PHP's CLI feature to interpret shell scripts, we assume that you have fair understanding of PHP and that PHP is installed and working properly on your computer, you can have PHP installed on Linux or Windows (the examples in this tutorial are demonstrated with PHP installed under Windows but they should work the same on Linux machine)