Table of Contents Previous Next
Logo
Ice Extension for PHP : 24.2 Introduction
Copyright © 2003-2008 ZeroC, Inc.

24.2 Introduction

PHP is a general-purpose scripting language that is used primarily in Web development. The PHP interpreter is typically installed as a Web server plug-in, and PHP itself also supports plug-ins known as "extensions." PHP extensions, by definition, extend the interpreter’s run-time environment by adding new functions and data types.
The Ice extension for PHP, IcePHP, provides PHP scripts with access to Ice facilities. IcePHP is a thin integration layer implemented in C++ using the Ice C++ run-time library. This implementation technique has a number of advantages over a native PHP implementation of the Ice run-time:
1. Speed
The majority of the time-consuming work involved in making remote invocations, such as marshaling and unmarshaling, is performed in compiled C++, instead of in interpreted PHP.
2. Integration
IcePHP is fully self-contained. Its installation is performed once as an administrative step, and scripts have no dependencies on external PHP code.
3. Reliability
By leveraging the well-tested Ice C++ run-time library, there is less likelihood that new bugs will be introduced into the PHP extension.
4. Flexibility
IcePHP inherits all of the flexibility provided by the Ice C++ run-time, such as support for SSL, protocol compression, etc.

24.2.1 Capabilities

IcePHP supplies a robust subset of the Ice run-time facilities. PHP scripts are able to use all of the Slice data types in a natural way (see Section 24.4), make remote invocations, and use all of the advanced Ice services such as routers, locators and protocol plug-ins.

24.2.2 Limitations

The primary design goal of IcePHP was to provide PHP scripts with a simple and efficient interface to the Ice run-time. To that end, the feature set supported by IcePHP was carefully selected to address the requirements of typical PHP applications. As a result, IcePHP does not support the following Ice features:
• Servers
Given PHP’s primary role as a scripting language for dynamic Web pages, the ability to implement an Ice server in PHP was deemed unnecessary for the majority of PHP applications.
• Asynchronous method invocation
The lack of synchronization primitives in PHP greatly reduces the utility of asynchronous invocations.
• Multiple communicators
A script has access to only one instance of Ice::Communicator, and is not able to manually create or destroy a communicator. See Section 24.4.11 for more information.

24.2.3 Design

The traditional design for a language mapping requires the intermediate step of translating Slice definitions into the target programming language before they can be used in an application.
IcePHP takes a different approach, made possible by the flexibility of PHP’s extension interfaces. In IcePHP, no intermediate code generation step is necessary. Instead, the extension is configured with the application’s Slice definitions, which are used to drive the extension’s run-time behavior (see Section 24.3).
The Slice definitions are made available to PHP scripts as specified by the mapping in Section 24.4, just as if the Slice definitions had first gone through the traditional code-generation step and then been imported by the script.
There are several advantages to this design:
• The development process is simplified by the elimination of the intermediate code-generation step.
• The lack of machine-generated PHP code reduces the risk that the application’s type definitions become outdated.
• Although PHP is a loosely-typed programming language, the Slice definitions enable IcePHP to validate the arguments of remote invocations.
Table of Contents Previous Next
Logo