PHP5 Upgrade Information

From apnsGuide

Jump to: navigation, search

Contents

Overview

Effective November 1, 2007 all servers will be using PHP 5.2 as the primary interpreter on port 80. PHP4, the previous interpreter on port 80, will be switched to port 9000 and retired on January 1, 2008 or once PHP6 enters production-ready status (includes unicode support), whichever happens last. Transitioning from PHP4 to PHP5 should have minimal impact on the usability of your site, so long as you are running relatively recent versions of your applications or if you wrote your own code, follow a few practical guidelines on backwards compatibility.

The PHP development made the official announcement on July 13, 2007. Although PHP4 will continue to have updates released to address only critical security holes, we feel that the benefits from diligence in keeping up with the advancements in Web hosting far outweigh the cons in advancing our services. Progress is marked by change and retiring an obsolete version is one of many changes that will benefit everyone one month down the road.

PHP5 may be used as the interpreter of choice on your Web site through a collection of mod_rewrite rules in the .htaccess file. Specific instructions may be found in the PHP section of the Wiki. Switchover from PHP4 to PHP5 should be transparent; however though, you are welcomed to access your Web site directly at http://domain:9000/. Subdomains may also be tested by replacing domain with subdomain.domain.

New Features in PHP5

Our goal is to make the transition as transparent as possible. Modules will not be removed unless obsoleted by the PHP developers. Several new additions will grace the installations:

  • filter - a sanitization extension
  • mysqli - improved MySQL interface
  • MySQL/PostgreSQL PDO - unified database abstraction layer (think DBI for Perl)
  • sqlite support - not quite sure why users requested this...


Caveats

Because we will be upgrading from PHP 4.4 to PHP 5.2, there will be multiple levels of potential conflict with code and PHP's internal engine changes. Below we have included the basic changes that may apply to you. Server migration should be transparent, but these are provided as warnings that will affect a small percentage of users.

4.4 => 5.0

PHP's list of backwards incompatible changes outline the major changes between PHP4 and PHP 5.0. From experience, the number one problem in transitioning occurs when using $this in reassignment, e.g.

<?php
   $some_other_object = new Foo(); 
   $this = $some_other_object;
?>
. Fixing that problem requires significant refactoring that is beyond the scope of the migration notes. Most vendors should have a workaround with that assignment in later versions.

A new error level, E_STRICT, was introduced in 5.0 as a way of enforcing forward compatibility with future versions of PHP. By default, this is not part of the default error reporting level on the server. E_ALL does not include E_STRICT, but a personal recommendation is to use E_STRICT to ease potential problems in future PHP versions. Reporting levels are most easily modified by adding a php_value directive to the .htaccess:

php_value error_reporting 6143
.

Note: Constants will not work in a .htaccess file. The idiom E_ALL&E_STRICT would be interpreted as the literal, which is 0.

An improved MySQL interface coincidentally named mysqli was introduced in PHP5. Backwards compatibility with mysql_*-style functions exists, but you are recommended, if supported by the application, to switch the MySQL interface type from mysql to mysqli.

DOM XML and Sablotron XSLT were succeeded by DOM and XSL respectively. Migrating to PHP5 will require a refactor of your code. Extensions reside in PECL, but we highly recommend against using an extension as a long-term solution.

5.0 => 5.1

PHP 5.1 went through an engine rewrite that primarily affects reference handling and date/time assignment. You may override the default timezone (EST5EDT) through date_default_timezone_set. Timezones may be configured for an entire directory recursively by using date.timezone in the .htaccess file. For example, to set the timezone affinity to MST with daylight saving time, the following would suffice:

php_value date.timezone MST7MDT

5.1 => 5.2

PHP 5.2 introduced the filter extension among other changes. This extension is aimed at providing programmers with a secure and reliable way of sanitizing input. By default, raw mode is set which means input passed from the browser to code is untouched. A personal recommendation would be, as a freelance developer, to make liberal use of the extension to safeguard against injections.

Personal tools