Chapter 16: Command-Line (Managed web hosting) PHP Utilities 561 These options

Chapter 16: Command-Line PHP Utilities 561 These options are not necessary for running command-line scripts because most command-line scripts under a Linux/UNIX system are run by adding the interpreter path as the first line. For example, Listing 16-1 shows a simple PHP script called helloworld.php. Listing 16-1: helloworld.php #!/usr/bin/php -q In PHP Version 4.3.x, the -q option is not needed if the PHP binary is compiled with the –enable-cli option, which enables Command Line Interface (CLI) support and automatically suppresses HTTP headers. Earlier versions of PHP supported multiple options, but only one option would actually work. In the preceding code, the first line starts with #! and is followed by the fully qualified path name of the PHP command-line interpreter. The next line is the starting tag for the PHP script. After making the file executable by running the chmod 755 helloworld.php command, you can run it from the script s current directory as follows: ./helloworld.php Following is sample output: Hello World When the helloworld.php script is run from the shell, the shell loads this file and locates the first line (#!, called the bang line) and runs the script using the named interpreter. All the scripts discussed in this chapter run this way. However, you can also run PHP scripts as follows: php q filename.php where filename.php is your script.

Leave a Reply