2/12/13

Where to Find PHP and More


You can find PHP at http://www.php.net/. PHP is open-source software, which means you won't need your credit card when you download it.

The PHP Web site is an excellent resource for PHP coders. The entire manual can be read online at http://www.php.net/manual/, complete with helpful annotations from other PHP coders. You can also download the manual in several formats.

You can find out more about getting Linux for your computer at 
http://www.linux.org/help/beginner/distributions.html. If you want to run Linux on a Power PC, you can find information about Yellow Dog Linux at http://www.yellowdoglinux.com/. Mac OS X, Apple's latest operating system, is based on Unix BSD and can run PHP with no problems. If you are running OS X, you can find installation information at http://www.php.net/manual/en/install.macosx.php.

If you want to run PHP with Windows, you can find complete installation instructions at http://www.php.net/manual/en/install.windows.php.

MySQL, one of the two databases we will use in this book, can be downloaded from http://www.mysql.com. Versions are available for many operating systems, including Unix, Windows, and OS/2.

Platforms, Servers, Databases, and PHP

Platforms, Servers, Databases, and PHP

PHP is truly cross-platform. It runs on the Windows operating system; most versions of Unix, including Linux; and Macintosh OS X. Support is provided for a range of Web servers including Apache (itself open-source and cross-platform), Microsoft Internet Information Server, WebSite Pro, the iPlanet Web Server, and Microsoft's Personal Web Server. The latter is useful if you want to test your scripts offline on a Windows machine, although Apache can also be run on Windows.

On most servers PHP can be installed as a server module. In other words, it runs as part of the server process rather than as a separate application. PHP is also installed as a standalone command-line application.

In this book, we will concentrate on building Web applications, but do not underestimate the power of PHP as a general scripting tool comparable to Perl. The fact that PHP runs as a command-line application means that any server that supports CGI scripts should be able to work with it. Configuration, though, will vary from server to server.

PHP is designed to integrate easily with databases. This feature is one of the factors that makes the language such a good choice for building sophisticated Web applications. PHP supports almost every database currently available, either directly or via Open Database Connectivity (ODBC).

Throughout this book, we will use a combination of Linux, Apache, and MySQL. We will also introduce SQLite, a lightweight but powerful SQL library that is newly bundled with PHP 5. All these are free to download and use and can be installed relatively easily on a PC.

The Zend Engine


When PHP 3 was written, an entirely new parser was created from the ground up. The introduction of PHP 4 represented a similar revolution in the code base. Zend is a scripting engine that sits below the PHP-specific modules. It was optimized to ensure massively improved performance and extensibility.

PHP 5 brings new fundamental improvements with the introduction of the Zend Engine 2. We have already touched on the great change ushered in by ZE2. The engine provides significantly enhanced support for object-oriented programming. For the first time, objects and object-oriented design lie at the heart of PHP, making it an even more suitable platform for large enterprise applications.

Performance

Because of the powerful Zend engine, PHP shows solid performance compared with other server scripting languages, such as ASP, Perl, and Java Servlets, in benchmark tests. To further improve performance, you can acquire a caching tool (Zend Accelerator) from http://www.zend.com/; it stores compiled code in memory, eliminating the overhead of parsing and interpreting source files for every request.

Portability

PHP is designed to run on many operating systems and to cooperate with many servers and databases. You can build for a Unix environment and shift your work to NT without a problem. You can test a project with Personal Web Server and install it on a Unix system running on PHP as an Apache module.

What's New in PHP 5


PHP 5 introduces numerous new features that will make the programmer's life more interesting. Let's take a quick look at some of them. If they don't make sense to you now, don't worry, we cover all these features in detail in this book:

  • PHP has new integrated for support for XML. The various functions and classes provided to handle XML in different ways all now use the same underlying library (libxml2). This should make XML features more stable and interoperable.
  • The SQLite SQL library is now bundled with PHP, together with all the functions you need to work with it.
  • PHP now supports private and protected methods and properties in classes.
  • PHP supports class constants.
  • Objects passed to functions and methods are now passed by reference. That is, a reference to an object is passed around your script rather than copies of objects. This significantly reduces the likelihood of bugs in object-oriented code.
  • PHP supports static methods and properties, making more advanced object-oriented designs possible.
  • Methods can now be declared to require particular object types.
  • The comparison operator (===) now checks that two references point to the same object. Previously, it was hard to test objects in this way.
  • PHP now supports abstract classes and interfaces.
Many of these improvements are due to some fundamental changes under the hood.

PHP: From Home Page to Web Enterprise.(Part-1)


You'll Learn:
  • What PHP is
  • About PHP's history
  • What improvements can be found in PHP 5
  • Some options that add features to your PHP binary
  • Some reasons you should choose to work with PHP
Welcome to PHP! you will look at almost every element of the PHP language. But first, you will explore PHP as a product its history, features, and future.

What PHP is:

PHP is officially known as PHP: Hypertext Preprocessor. It is a server-side scripting language often written in an HTML context. Unlike an ordinary HTML page, a PHP script is not sent directly to a client by the server; instead, it is parsed by the PHP engine. HTML elements in the script are left alone, but PHP code is interpreted and executed. PHP code in a script can query databases, create images, read and write files, talk to remote servers—the possibilities are endless. The output from PHP code is combined with the HTML in the script and the result sent to the user.

PHP is also installed as a command-line application, making it an excellent tool for scripting on a server. Many system administrators now use PHP for the sort of automation that has been traditionally handled by Perl.

What Need Does PHP Fulfill?

There have been scripting solutions for as long as there has been a World Wide Web. As the need to create sites with dynamic content has grown in recent years, so has the pressure to create robust environments quickly and efficiently. Although C can be a great solution for creating fast server tools, it is also hard to work with and can easily produce security holes if not carefully deployed. Perl, a language originally developed for text processing naturally met the demand for dynamic Web environments. Much easier to deploy safely than C, its slower performance has always been more than balanced by the comparatively fast development cycle it offers. Even more useful has been the increasing availability of a large number of stable code libraries for Perl.

So where does PHP fit in? PHP was written especially for the Web. Many of the issues and problems faced by Web programmers are addressed within the language itself. Whereas a Perl programmer must use an external library or write code to acquire data submitted by the user of a Web page, PHP makes this data automatically available. Whereas a Perl programmer must install modules to enable her to write database-driven environments, PHP bundles a powerful SQL database library and provides built-in support for a whole range of third-party databases. In short, because PHP has been created for Web programmers, it has a set of functions for almost any typical problem you might encounter, from managing user sessions to handling XML documents.

So, do we have to pay for this ease of use with even slower performance? Not at all. PHP is designed to run as a module with many server applications, which means that there are none of the start-up overheads associated with CGI scripts. The fact that many typical tasks are handled by PHP means that developers are freed from reliance on utility libraries that can slow things down.

It is not the case that PHP does not provide libraries, though. Perl has the Comprehensive Perl Archive Network (CPAN), and PHP has the PHP Extension and Application Repository (PEAR)—its own repository of powerful packages that extend PHP's power.

Introducing PHP and MySQL


Enter PHP and MySQL. These two make up what must be the best combination for data-driven Web sites
on the planet. You needn't take my word for it. An unofficial Netcraft survey shows that PHP usage has
jumped from 7,500 hosts in June 1998 to 410,000 in March 1999. That's not bad. The combination was also awarded Database of the Year at Webcon98, where it received a lovely tiara.

MySQL is a small, compact database server ideal for small - and not so small - applications. In addition to
supporting standard SQL (ANSI), it compiles on a number of platforms and has multithreading abilities on
Unix servers, which make for great performance. For non-Unix people, MySQL can be run as a service on
Windows NT and as a normal process in Windows 95/98 machines.

PHP is a server-side scripting language. If you've seen ASP, you'll be familiar with embedding code within an
HTML page. Like ASP, PHP script is processed by the Web server. After the server plays with the PHP code, it returns plain old HTML back to the browser. This kind of interaction allows for some pretty complex operations.

In addition to being free (MySQL does have some licensing restrictions though), the PHP-MySQL
combination is also cross-platform, which means you can develop in Windows and serve on a Unix platform.
Also, PHP can be run as an external CGI process, a stand-alone script interpreter, or an embedded Apache
module.

If you're interested, PHP also supports a massive number of databases, including Informix, Oracle, Sybase,
Solid, and PostgreSQL - as well as the ubiquitous ODBC.

PHP supports a host of other features right at the technological edge of Internet development. These
include authentication, XML, dynamic image creation, WDDX, shared memory support, and dynamic PDF
document creation to name but a few. If that's not enough, PHP is easy to extend, so you can roll your
own solution if you're programming savvy.

Finally, since both efforts are collaborative in nature, there's always plenty of support from documentation
and mailing lists. Bugs are fixed rapidly, and requests for features are always heard, evaluated, and if
feasible, implemented.