Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Simple System Maintenance with PHP-CLI

By Akash Mehta
2008-01-21


Simple System Maintenance with PHP-CLI

Web development is a world of rapid code modifications, instant deployment and immediate updates. Of course, maintaining the product of this web development can be as hectic as the web development is agile; with manual backups, quick database edits and tedious data migration and re-entry. In this tutorial, I'll show you how to use PHP-CLI, the command line interface for PHP, to get your maintenance under control using the technologies you're already familiar with. By the time you've finished this tutorial, you'll be able to build human-assisted backup systems, automatic report generators.

Prerequisites

As you follow this tutorial, I'll presume you're familiar with the basics of PHP, and have built practical software with it – this tutorial is about maintaining that practical software. You don't actually need anything to maintain to follow this tutorial, however; just read through and experiment with the code snippets.

As we're working with PHP from command line, access to the command line of a system with PHP is essential; if you don't have this yet, see the "Quick setup' section below. Basic command line knowledge is highly recommended as well.

Finally, being able to recognise a SQL query helps but is not at all required; we'll be interacting with a database later in the tutorial.

Quick setup

If you're on a shared host, or an old server, you may not have access to a console with PHP; testing with your local machine might be easiest. If you're on Windows, XAMPP Lite is a great way to get up and running with a disposable web server with PHP CLI. XAMPP is also available for Linux systems but you're probably better off with your distribution's package manager – an apt-get php5 would do on Ubuntu/Debian, for example, and this will also put the binaries in the right locations. To be able to run PHP by simply calling the PHP binary at your console, you'll need to add your PHP directory to your PATH environment variable; try this guide for Windows and this guide for UNIX if you aren't familiar with this. Finally, depending on your PHP configuration, you may find that you need to suppress the HTTP headers, which obviously won't be of much use on the console. Instead of the php used in this guide, try running php –q if you find you're getting content-type or similar headers before your output.



Tutorial Pages:
» Simple System Maintenance with PHP-CLI
» Fundamentals
» PHP-CLI 101
» Get Maintaining!
» Sample Scripts
» Have Fun!


Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1

Ask A Question
characters left.