Today's PHP tip: command line version
Did you know that PHP isn't just for the web?
While building dynamic web pages and applications is by far the most common use for PHP, it can also be handy for non-web-related scripting. Because PHP gives you the capability to manipulate files and execute system commands, it can be used to perform just about any task you can imagine: making (and even emailing) nightly backups of important data, clearing tempfiles, rotating logs, creating MySQL dumps... And of course all the specialized jobs which need to be run on your particular server.
In order to use PHP for scripting apart from the web, you'll need to install the binary, or "command line" version. To do so, simply ./configure PHP without specifying a "--with-apache=" flag, then make and make install. Once the binary is installed, the `php` command will run a script.
For example, suppose you have a file called hello.php which contains
<?
echo "Hello, world!\n";
?>
From the command line, you'd run:
>$ php hello.php
The output will appear in your shell. No web browser - not even a web server - is needed!
Looking for quality PHP scripts at a price that won't break the bank?
Check out
PHP Labs for professional scripts and thousands of webmaster resources.