Using PHP for Sysadmin TasksCHAPTER 16 Command-Line PHP Utilities CHAPTER 17 Apache Virtual Host Maker CHAPTER 18 BIND Domain Manager Part IV... Chapter 16Command-Line PHP Utilities IN
Trang 2Using PHP for Sysadmin Tasks
CHAPTER 16
Command-Line PHP Utilities
CHAPTER 17
Apache Virtual Host Maker
CHAPTER 18
BIND Domain Manager
Part IV
Trang 4Chapter 16
Command-Line PHP Utilities
IN THIS CHAPTER
◆ Writing command-line PHP utilities
◆ How to create a cron-based reminder
◆ How to develop a geographic location query tool for IP
◆ Developing a spam-busting utility for POP3 mailboxes
◆ How to develop a hard disk monitoring tool
◆ Creating a CPU load monitoring tool
PHP STARTED OUT AS A SIMPLEWeb scripting tool written in Perl and later became the most popular Web application development language Because of its strong ties with the Web, it has lagged behind as an all-purpose programming language
Especially for command-line users, PHP is considered a newcomer, because not many command-line PHP utilities are floating around on the Internet just yet In this chapter, you develop a few command-line utilities to get you started in command-line PHP development
Most of the scripts discussed here might not work on a Windows platform.
They have been tested on the Linux platform only.
559
Trang 5Working with the Command-Line Interpreter
The command-line version of PHP is installed when you enable CGI support during the PHP installation process The command-line PHP interpreter can be found by running the following:
which php
This will show the full path of the PHP command-line interpreter Sample output appears as follows:
/usr/bin/php
In most cases, you should find the PHP binary in the /usr/bin directory, which is typically in your path, so you can run the following:
php -h
The 4.3.x version of the PHP command-line interpreter will display output simi-lar to following:
Usage: php [options] [-f] <file> [args ]
php [options] -r <code> [args ]
php [options] [ args ]
-s Display color syntax highlighted source.
-w Display source with stripped comments and whitespace.
-f <file> Parse <file>.
-v Version number -c <path>|<file> Look for php.ini file in this directory -a Run interactively
-d foo[=bar] Define INI entry foo with value ‘bar’
-e Generate extended information for debugger/profiler
-z <file> Load Zend extension <file>.
-l Syntax check only (lint) -m Show compiled in modules -i PHP information
-r <code> Run PHP <code> without using script tags <? ?> -h This help
args Arguments passed to script Use args when first argument
starts with - or script is read from stdin
560 Part IV: Using PHP for Sysadmin Tasks