© 2006 IBM Corporation
New York PHP Conference & Expo 2006
®
1
Using PHP and SOA for Situational Applications in the Enterprise Mike [email protected] DeveloperWebSphere Technology InstituteIBM
New York PHP Conference & Expo 20062
Goals
Explore how PHP best fits in the enterprise. What
works well, what doesn’t, what needs to be fixed?
Propose some technologies, tools and approaches
that we believe will help PHP reach its full potential in
the enterprise environment.
Get feedback from the PHP community. Do you think
we’re on the right track?
New York PHP Conference & Expo 20063
Application Landscape Overview
Situational / Opportunistic
Applied to a new or still-changing environments
Focus on effectiveness
Key metrics: time-to-productive-use, good-enough
Lifespan expectation: short
Basis: mostly Information Delivery, some Business Process
Source: situated design / custom development
Decision Maker: partnership, primarily LOB
Systematic / Operational
Applied to stable, well-understood environments
Focus on efficiency
Key metrics: cost / ROI, performance, error-free, secure
Lifespan expectation: long-lived
Basis: mostly Transactional, some Business Process
Source: packaged software, minor modification, a few custom
Decision Maker: partnership, primarily IT (In-
House or Bus Partner)
Growth in # of Apps
New York PHP Conference & Expo 20064
Shifting focus
Enterprise IT has traditionally focused toward the systematic end of the spectrum, but several forces are pushing them to incorporate the entire spectrum into their thinking:
Increasing speed of business is translating to immediate need and shorter expected lifespan for applications.
Difficulty adapting current IT processes and methodologies that assume greater up-front investment in application and amortization over long application lifespan.
New technologies enabling classes of applications with real business value that are a better match for the technologies at the situational app end of the spectrum (e.g. mashups).
Economies of scale from consolidating infrastructure used to deploy situational apps
Need to audit application use of data, e.g. for governmental regulations
New York PHP Conference & Expo 20065
PHP and SOA
The combination of PHP and SOA is a good solution for these situational applications, but there are gaps between enterprise IT and PHP that need to be addressed to allow PHP to be an equal player in the enterprise IT space:
Programming model
Development and deployment model
Management model
Enterprise class QoS
BUT…we must not destroy the things that make PHP appealing in the process of addressing these gaps.
New York PHP Conference & Expo 20066
Training Tracker
As an example, consider the needs of the accounting department in a large enterprise that needs to put all its employees through a training program offered by an external vendor to make the employees aware of some recently established accounting rules. The accounting department would like a Training Tracker application that allows employees to enroll and schedule their training and managers to track the successful completion of training by all their employees.
New York PHP Conference & Expo 20067
Training Tracker architecture
Training
Tracker
Employee
directory
Education
service
corporate network
internet
New York PHP Conference & Expo 20068
Programming Model for PHP Enterprise Applications
Be simple and thus enable developers who have a much better
understanding of business issues as compared to IT issues.
Insulate the developer from underlying SOA implementation
technologies, such as XML, WSDL, SOAP and REST.
Provide a unified API for data from various data sources in a
SOA environment, such as XML, databases and legacy
applications.
Provide a unified API for invoking different types of service
implementations in a SOA environment, such as REST and
SOAP.
New York PHP Conference & Expo 20069
SDO (Service Data Objects)The bundle of technology called SDO is comprised of:
APIs for working with the data in an individual SDO
APIs for creating SDOs, hooking them into a graph, unsetting them…
An XML DAS: a handful of lines of code to get data from XML and turn it into a graph of SDOs, one line to write it back out
Like DOM but a lot easier to use
A handful of lines to get data from a relational database and turn it into a graph of SDOs, one line to write it back
Work with the data in the same way regardless of source
A graph of SDOs is disconnected from the data source but retains a change history and a copy of its initial values (enables optimistic offline lock – see Fowler "Patterns of Enterprise Application Architecture")
Readily serialised and un-serialised – hence a preferred way to move structured data around in distributed (SOA) applications
New York PHP Conference & Expo 200610
Training Tracker SDO example
<?php
/*****************************************************************
* METADATA DEFINING THE DATABASE
******************************************************************/
$training_table = array (
'name' => „training',
'columns' => array(„empid', „trainingDate'),
'PK' => „empid'
);
$database_desc = array($training_table);
?>
New York PHP Conference & Expo 200611
require_once 'SDO/DAS/Relational.php';
/***************************************************************
* Construct the DAS with the metadata
***************************************************************/
$das = new SDO_DAS_Relational($database_desc);
/**************************************************************
* Get a database connection
***************************************************************/
$dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD);
/**************************************************************
* Issue a query to obtain an object for a row
***************************************************************/
$pdo_stmt = $dbh->prepare('select empid, trainingDate from training where empid=?');
$root = $das->executePreparedQuery($dbh, $pdo_stmt, array($empid));
$training = $root->training[0];
New York PHP Conference & Expo 200612
// Mary has scheduled her training
$training->trainingDate = “June 23, 2006”;
require_once 'SDO/DAS/Relational.php';
/**************************************************************
* Construct the DAS with the metadata and get a connection
***************************************************************/
$das = new SDO_DAS_Relational($database_desc);
$dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD);
/**************************************************************
* Write the updates to the database. $root is the original root
* data object returned during retrieval of the training information.
***************************************************************/
$das->applyChanges($dbh, $root);
New York PHP Conference & Expo 200613
SCA (Service Component Architecture)
Simplifies application assembly by resolving references
to other components and services at runtime
Uses SDO to simplify working with complex XML data
structures on Web service calls
Simplifies writing components which can be called
locally or remotely (via Web services)
Automatically generates WSDL definitions from
annotations within the script
New York PHP Conference & Expo 200614
Training Tracker Component
Training Tracker component aggregates the other services
and database information
/**
* @service
*/
class TrainingTracker {
/**
* @reference http://empdir.mycompany.com/empdir.wsdl
*/
$empdir;
/**
* @reference http://websvc.we-teach.com/courseschedule.wsdl
*/
$courses;
...
New York PHP Conference & Expo 200615
Training Tracker Component (continued)
function showStatus($manager) {
foreach ($empdir->reportsTo($manager) as $employee) {
// fetch training record for $employee->id as shown in
// SDO example above
if ($training->trainingDate) {
print $employee->name.”:”.$training->trainingDate;
}
else {
print $employee->name.”: training still available on”.
$courses->datesAvailable(COURSE);
}
}
}
}
New York PHP Conference & Expo 200616
Development and Deployment Model
Developing an application is only part of the problem.
How do you make an application available to users?
Staged mode – copy application artifacts from development
environment to production environment
Direct mode – use the same environment for both development
and production
?
New York PHP Conference & Expo 200617
The Packaging and Installation Problem
Packaging of PHP applications today is ad-hoc.
Many of the more mature PHP applications
seem to be converging on a common pattern:
1. Application files packaged as .zip or .tar.gz archive
2. Users extract archive, then point web browser to
application install script (e.g. install.php)
3. Install script collects configuration information and
inspects/modifies environment to complete install
4. User performs some manual steps (e.g. cleanup install
directory) to indicate install/configuration is complete
install.php
config.php
New York PHP Conference & Expo 200618
Proposed solution
Solution needs to minimally ensure the following:
consistent settings in the PHP environment (php.ini)
database has the correct schema and all the pre-
loaded data that the application depends on
constants in the PHP application scripts that are used
for things like establishing database connections,
writing to temporary storage, etc. are set
correct set of PEAR and PECL libraries (with the right
versions) are available
New York PHP Conference & Expo 200619
Proposed solution
Use PHPDoc tags to flag variables that need
to be set to configure the application.
Packaging tool that collects the following into
an application archive file:
application files (scripts and static content)
database schema and initial data
install.php script generated from PHPDoc
tags
information about PEAR/PECL libraries
needed and php.ini settings
.html,
.gif,… .php
install.php
pa
cka
gin
g
too
l
.tar.gz
PEAR/PECL and
php.ini info
New York PHP Conference & Expo 200620
Training Tracker install.php example/**
* Database password
*
* Set the value to the password used to access the Training Tracker
* database.
*
* @install
*/
define('DATABASE_PASSWORD', 'mydbpassword');
/**
* Some other variable
*
* This text would describe what myvar is used for and how the administrator
* should determine what to set it to.
*
* @global integer $GLOBALS['othervar']
* @install
*/
$GLOBALS['othervar'] = 42;
New York PHP Conference & Expo 200621
Training Tracker install.php example
New York PHP Conference & Expo 200622
Management model
PHP developers like advantages of “under the desk” deployment:
Simple to monitor app and correct operational problems as necessary
Application trivially upgraded to handle bug fixes, enhancements and new requirements
But this model does not match the needs of enterprise IT department:
No ability to monitor or manage application and its impacts on other IT infrastructure (use of enterprise services, for example)
Limited/no ability to track application usage for billing and regulatory compliance purposes
No ability to assess backup and security provisions for application
New York PHP Conference & Expo 200623
Private Virtual Servers
Modeled after PHP hosting provided by ISPs
PHP developer requests virtual PHP server from
enterprise IT
Server is hosted on IT infrastructure; developer uses
web-based console and WebDAV to access
Includes database space and simplified access to
enterprise services (code snippets, preconfigured
client code, etc.)
New York PHP Conference & Expo 200624
Benefits
Developer
essentially the same experience as with a local LAMP stack
gets enterprise-level backup, failover, security and support
IT
gains ability to monitor and manage application
distributed shared caching
simplified migration path when situational applications become strategic
New York PHP Conference & Expo 200625
QoS Dynamically adjust number
of instances of application
in response to demand and
administrative policy
Impact of application on
enterprise services can be
measured, monitored and
controlled
Access to application can
be controlled and audited
for regulatory or billing
purposes
Training
Tracker
Employee
directory
Training
Tracker
Training
Tracker
Core
enterprise
app
SPEED
LIMIT
20
SPEED
LIMIT
20
SPEED
LIMIT
70
New York PHP Conference & Expo 200626
Conclusion
The combination of PHP and SOA has the potential to
address the rapidly-expanding need for situational
applications in the enterprise. With a few carefully
crafted changes, PHP and enterprise IT can converge
in a way that lets users capitalize the strengths of
each.
New York PHP Conference & Expo 200627
Further reading
PHP topics on developerWorks
http://www-128.ibm.com/developerworks/opensource/top-projects/php.html
SDO
http://www-128.ibm.com/developerworks/library/os-sdophp/
http://www-128.ibm.com/developerworks/opensource/library/os-php-sdo/
http://www.php.net/manual/en/ref.sdo.php
SCA
http://www-128.ibm.com/developerworks/library/specification/ws-sca/ (although
we expect PHP SCA will be much simpler than the Java and C++ examples
you see here)
New York PHP Conference & Expo 200628
New York PHP Conference & Expo 200629
Thanks!
If you have any questions or would like to get in touch
with me, my email address is: