Ice for PHP

PHP is a popular open source scripting environment that is used primarily for interactive Web applications. Ice for PHP extends that functionality to integrate Web-based front-ends with Ice services, enabling the development of powerful Web services that leverage the Ice platform to interoperate with back-end applications using any supported language and operating system.

Web Applications

As an extension of a Web server's processing pipeline, PHP scripts are embedded directly in HTML pages. Incorporating Ice into the mix enables PHP developers to dynamically invoke operations on back-end Ice services and format the results into HTML content.

Sample Code

Here is a simple script that displays a stock quote obtained from an Ice service:

   <TITLE>Stock Quote</TITLE>
   require 'Quoter.php';
   $communicator = Ice_initialize();
   $proxy = $communicator->stringToProxy("QuoterObject");
   $quoter = Demo_QuoterPrx::checkedCast($proxy);
   $price = $quoter->getQuote($_POST["symbol"]);
   printf("<B>Current price:</B> $%.3f\n", $price);

As the Web server processes this page for a client, the PHP code embedded within the <?php and ?> tags is replaced with the output of the script. Combining PHP and Ice in this way offers tremendous potential for creating dynamic content and sophisticated Web applications.

To illustrate how Ice is used with PHP, consider the following Slice interface definitions:

module Biz {
    struct Item {
        string sku;
        int qty;
    sequence<Item> ItemSeq;
    interface Invoice {
        void addItems(ItemSeq items);
        void submit();
    interface InvoiceFactory {
        Invoice* create();

PHP code that creates an invoice using the factory is shown below:

// Create a proxy for the invoice factory object.
$proxy = $communicator->stringToProxy("InvoiceFactory:tcp -p 9000");

// Narrow the proxy to the proper type.
$factory = Biz_InvoiceFactoryPrx::checkedCast($proxy);

// Use the factory to obtain a proxy for a new invoice object.
$invoice = $factory->create();

// Add items to the invoice.
$item = new Biz_Item;
$item->sku = "10-6139";
$item->qty = 3;
$items = array($item);

// Submit the invoice.
Terms of Use | Privacy | Software License © 2015 ZeroC, Inc.