PHP is a very powerful, flexible, and productive general purpose language that is commonly embedded within HTML pages to provide dynamic user interfaces. PHP has an exceptionally short learning curve, and support for Linux, Unix, Windows, and other major platforms. It is free, lightweight, and able to resolve complex Web programming problems because it contains a myriad of built-in functions. There is also a large active community of developers available and ready to address any critical bugs or problems as they arise. These, and other, numerous advantages have led to its rapid worldwide adoption for use on the Web.
PHP code is interpreted at run timenot compiled, and uses syntax similar to C++, Perl, and JavaScript to navigate the source code. Once a PHP page is written, it can be viewed identically from any operating system or hardware platform. Experienced and novice developers quickly become productive using PHP within a few hours. With its fast deployment cycles, PHP is ideal for companies short on skilled programming resources and/or facing tight time to market deadlines. PHP’s features and benefits are so compelling it should be considered for your SOA solutions.
Moving PHP Into the Enterprise for SOA Applications
If you dream of using PHP to develop more than scripts, you will be glad to know that IBM has made four recent, significant contributions to help you use PHP for your SOA applications, to create messaging and queuing systems, and for other business processes.
First, IBM has combined PHP technology with its open source-based application serverIBM WebSphere Application Server Community Edition (WAS CE). IBM’s PHP Integration Kit for WAS Community Edition lets you utilize the benefits of both PHP and Java for developing and executing services inside SOA. The PHP Integration Kit gives you the flexibility to create corporate Web sites that can dynamically access, use, and update information from a variety of global applications that run on a SOA.
The PHP Integration Kit provides a sample Web application containing a servlet filter that communicates with a PHP run-time environment using the FastCGI interface. The sample application is preconfigured to forward each PHP request, which executes the requested PHP script.
You download and install a PHP run-time environment and any necessary platform prerequisites. Using the WAS CE administration console, you can deploy, run, manage, and perform other activities on the application, as well as apply security constraints. You can also package the PHP application and modules using the kit's Web module template, which is preconfigured with the necessary deployment descriptors to invoke the PHP run-time environment and to forward PHP requests to that run-time environment.
Service Component Architecture and Service Data Objects
Next, IBM, working with vendors, including BEA, IONA, Oracle, SAP, Siebel and Sybase, and others, has created a number of specifications covering the development, assembly and deployment of SOA systems: Service Component Architecture (SCA) and Service Data Objects (SDO). One set of technologies following these specifications is the Service Component Architecture and Service Data Objects for PHP. These are open source implementations available in the PHP Extension Community Library (PECL).
SCA provides an open, technology-neutral model for implementing IT services that are defined in terms of a business function. SCA makes components more accessible to you. It provides a model for assembling business solutions from individual services giving you control over access methods and security.
For your SOA projects you can use SCA for PHP to use PHP to write reusable components and create Web services. The components written in PHP are unaware of local/remote and protocol differences. This simplifies the process of creating reusable components, which can be called either locally or remotely via Web services.
Components use extended phpDocumentor annotations both to declare their dependencies on other components, and to define the interface, which they expose as a service. The SCA for PHP runtime resolves these dependencies at runtime letting you focus on the business logic rather than on locating and obtaining references to dependencies. As mentioned, earlier, annotations are also used to define the interface, which is exposed as a service. The SCA for PHP runtime automatically generates WSDL from these annotations enabling an SCA component to be exposed as a Web service. You deploy a Web service by placing a PHP component under the document root of a Web server.
An SCA Component is similar to a PHP class. A simple example is listed below:
<?php
include 'SCA/SCA.php';
/**
* Service for sending emails
*
* @service
* @binding.ws
*/
class EmailService {
…
/**
* Send a simple text email
*
* @param string $to The "to" email address
* @param string $from The "from" email address
* @param string $subject The subject of the email
* @param string $message The email message
* @return boolean
*/
public function send($to, $from, $subject, $message) {
…
}
}
?>
SDO complements SCA by providing a common way to access many different kinds of data, such as XML, Relational and JSON. The numerous APIs that are used to manipulate data tend to tightly couple the source and target of the data, and require the developer to understand a new API for each. This makes them highly prone to errors and likely to fail as business requirements evolve. SDO makes it easier to use and realize the value of these APIs without having to specifically code to them.
SDO simplifies the process of accessing and manipulating business data and unifies the way in which applications handle data. SDOs let you uniformly access and manipulate data from different types of data sources, including relational databases, XML data sources, and Web services.
Simple Asynchronous Messaging Using PHP
Last but not least, IBM has created an extension to PHP called SAM that provides access to the functionality of messaging and queuing systems from PHP scripts. Reliable messaging and queuing processes are essential for connecting, communicating, and transporting information between applications and various business systems. Robust messaging and queuing systems remove the details of any network or communication technology from the sender and receiver applications and allows the sender and receiver to work asynchronously. They work across multiple network and operating system technologies, and scale to very large numbers of endpoints. These systems also work in conjunction with publish and subscribe processes that allow messages to be published and received according to specific criteria (or topics).
However, while the concepts of messaging are simple to understand, creating the APIs to these systems is not. A recent project called Simple Asynchronous Messaging (SAM) simplifies the process of accessing messaging and queuing systems by converting the APIs into scripting languages including PHP. SAM is an open source implementation available from PECLa repository for PHP extensions, providing a directory of extensions and hosting facilities for downloading and development of PHP extensions. SAM uses an API that is designed to be messaging system neutral.
The SAM extension has an interface designed to make it extremely simple to do commonly required tasks such as deliver simple text messages to queues while still allowing you to do more complex messaging operations. In most cases it allows you to simply ignore the complexities of having to set up numerous options. The SAM extension is a small, stateless extension written in C that can be built for either PHP 5 or PHP 4 and is available for download.
The SAM extension currently allows applications to access queues or use publish and subscribe with a broad range of the IBM Messaging and Queuing family of products including WebSphere MQSeries, WebSphere Application Server and WebSphere Event Broker.
The following is an example of how to send a message to a queue using PHP
// Create a connection
$conn = new SAMConnection();
if ($conn->connect(SAM_WMQ, array (SAM_BROKER => ‘MyBroker’))) {
//Create a message
$msg = new SAMMessage(‘Simple text message’);
//Send it
if (!$conn->send(‘queue://send/test’, $msg)) {
// Oh dear the send failed!
}
} else {
// Oh dear we didn’t successfully connect!
}
PHP Simplifies Your SOA Directives
IBM is making it easier to incorporate PHP into your SOA or enterprise environments and align your technology preferences with your business goals. So test drive these new PHP innovations and see how easy it is to use PHP to add more sizzle to your SOA applications.