PHP DevCenter
oreilly.comSafari Books Online.Conferences.

advertisement


O'Reilly Book Excerpts: PHP: Pocket Reference

PHP Pocket Reference

Related Reading

PHP Pocket Reference
By Rasmus Lerdorf

by Rasmus Lerdorf

An excerpt from PHP: Pocket Reference, a handy quick reference for PHP, an open-source, HTML-embedded scripting language that can be used to develop web applications.

Introduction

PHP is a server-side, HTML-embedded, cross-platform scripting language--quite a mouthful. In simpler terms, PHP provides a way for you to put instructions in your HTML files to create dynamic content. These instructions are read and parsed by the web server; they never actually make it to the browser that is displaying the page. The web server replaces your PHP code with the content that the code was written to produce.

PHP can be configured to run either as a server module or as a standalone CGI script. At the time of this writing, the server-module version is only production-ready for the Apache web server on Unix systems. The CGI version runs with all web servers on both Unix and Windows 95/98/NT. On the Windows platform (as of PHP Version 4), the server module is being developed to work with ISAPI, NSAPI, and WSAPI, which means the server module will eventually work with Microsoft's IIS, Netscape's Enterprise Server, and O'Reilly's WebSite. See http://www.php.net for availability details.

The PHP language itself borrows concepts from other common languages, such as C and Perl. If you have some experience with one of these languages, you should feel right at home with PHP. In addition to the core language, PHP provides a wide variety of functions that support everything from array manipulation to regular expression support.

Database connectivity is one popular use for PHP. PHP supports a large number of databases natively and many others are accessible through PHP's ODBC functions. Through this database connectivity, it is possible, for example, to take a company's database of products and write a web interface to it using PHP.

This book provides an overview of the core PHP language and contains summaries of all the functions available in PHP. The material covers PHP 3.0.

Installation and Configuration

PHP Version 3 can be installed in two primary ways: as an Apache module on Unix systems or as a CGI script on both Unix and Windows systems. See the installation instructions that come with PHP for full and current information.

When you are using PHP as an Apache module, PHP processing is triggered by a special MIME type. This is defined in the Apache configuration file with a line similar to:

AddType application/x-httpd-php3 .php3

This tells Apache to treat all files that end with the .php3 extension as PHP files, which means that any file with that extension is parsed for PHP tags. The actual extension is completely arbitrary and you are free to change it to whatever you wish to use.

If you are running PHP as a dynamic shared object (DSO) module, you also need this line in your Apache configuration file:

LoadModule php3_module    modules/libphp3.so

When you are running PHP as a CGI script (with any web server), PHP processing is still triggered by this special MIME type, but a bit more work is needed. The web server needs to know that it has to redirect the request for the PHP MIME type to the CGI version of PHP. With ApacheNT, for example, this redirect is done with a set of configuration lines like the following:

ScriptAlias /php3/ "/path-to-php-dir/php.exe" 
AddType application/x-httpd-php3 .php3
Action application/x-httpd-php3 "/php3/php.exe" 

For IIS, this redirect is set up through the Windows registry. Refer to the PHP installation instructions for full details.

At runtime, most aspects of PHP can be controlled with the php3.ini file (located in /usr/local/lib by default). For the Apache module version of PHP, this file is read only when the server is started or reinitialized. Changes to this file should be treated the same as changes to Apache's own configuration files. In other words, if you make a change, you need to send your Apache server an HUB or a USR1 signal before the change will take effect.

Many aspects of PHP can also be controlled on a per-directory basis (or even per-location or per-request) when using the Apache module version. Most of the directives available in the php3.ini file are also available as native Apache directives. The name of a particular directive is the php3.ini name with "php3_" prepended. For a list of all available Apache directives, run your Apache httpd binary with the -h switch.

Pages: 1, 2, 3, 4, 5

Next Pagearrow




Valuable Online Certification Training

Online Certification for Your Career
Earn a Certificate for Professional Development from the University of Illinois Office of Continuing Education upon completion of each online certificate program.

PHP/SQL Programming Certificate — The PHP/SQL Programming Certificate series is comprised of four courses covering beginning to advanced PHP programming, beginning to advanced database programming using the SQL language, database theory, and integrated Web 2.0 programming using PHP and SQL on the Unix/Linux mySQL platform.

Enroll today!


Sponsored by: