Project Zero PHP talk at JavaOne 2008.
This talk describes IBM WebSphere sMash and the PHP support within it. For more information visit http://www.projectzero.org
Value Proposition canvas- Customer needs and pains
Â
Project Zero JavaOne 2008
1. The Duke and the Elephant: PHP meets
JavaTM Technology. The best of both
worlds.
Rob Nicholson
.
IBM Senior Technical Staff Member
2. Agenda
Whys and Whats of PHP on the Java Virtual Machine
(JVMâ˘) software
How we mix PHP, Java platform and Groovy
Demonstration of PHP and Java Platform Interaction
ProjectZero Community
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 2
3. Agenda
Whys and Whats of PHP on the Java Virtual Machine
(JVMâ˘) software
How we mix PHP, Java platform and Groovy
Demonstration of PHP and Java Platform Interaction
ProjectZero Community
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 3
4. Why PHP?
PHP present on 20M+ web domains (34% of internet)
⢠Validated by significant web properties
PHP snippets and extensions exist to do almost anything
Language has evolved in open source
⢠Survival of the simplest and fastest
Simple syntax and dynamic typing encourage situational applications
Gartner (Dec 2007) TIOBE Programming Community Index (March 2008)
⢠PHP Developers to grow from 3
to 5.5 million by 2013
⢠PHP Developers in Commercial
or Corporate IT to grow from
13% to 60% by 2013
⢠âPay special attention to
opportunities to leverage PHP in
combination with Java
development effortsâ
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 4
5. Introducing WebSphere sMash
WebSphere sMash is an Agile Web Application Platform
⢠Architected around Dynamic Scripting, REST, Rich Web Interfaces,
AJAX, and Feeds
⢠Optimized for
⢠Speed
⢠Simplicity
⢠Agility
Key Scenarios
⢠Enables developers to build web 2.0-style applications by easily pulling in,
composing, and âcobbling togetherâ pre-existing assets (PHP assets, services,
feeds, code snippets) using dynamic scripting languages and simple
consumption principles based on REST
⢠Leverages existing SOA investments by enabling rapid development of dynamic
web applications that are assembled from enterprise assets and publicly
available APIs
System language is Java platform
Application languages are and
⢠Contains a PHP 5 interpreter written in Java programming language
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 5
6. Project Zero
Incubating the Technology
Project Zero is the development and incubation
community for WebSphere sMash
⢠Live on the Internet since June 2007
Project Zero represents
⢠The people that build and use WebSphere sMash
⢠The incubation of new technology that will deliver in future versions of
WebSphere sMash
⢠The community of 3rd party assets that leverage the WebSphere sMash platform
All released versions are called WebSphere sMash
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 6
7. The Duke and the Elephpant
Š Hideyuki Shimooka
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 7
8. Top Level Architecture
App components
Runtime
Dojo Events
PHP
HTTP server
app
Browser
REST
Global
Context
Runtime
app
Groovy
Local repository
Package
JavaTM app
Remote repository Manager
Remote repository Zero Application
Loose coupling: Java Virtual Machine
⢠Event driven architecture
⢠Global Context
⢠Virtual Directories
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 8
9. PHP Runtime Architecture
CLI PZ Http
PHP Scripts
⢠Runtime for PHP 5 scripts
SAPI-J
⢠Implemented in Java code, runs on any Java
platform 5.0+ VM
PHP Engine ⢠PHP language elements represented as Java code
Variables
Parser
Cache objects
Debug (DBGp)
Stack IR
P8 Runtime
⢠Parse script to Intermediate Representation (IR)
Resources ⢠Cache and Interpret IR
Interpreter
Classes ⢠Compile ->bytecode prototype
Objects Runtime
⢠Extensibility via XAPI
⢠XAPI-C for C extensions from php.net
XAPI-C
XAPI-J ⢠XAPI-J for new Java platform extensions,
Java
native libraries invoked over JNI⢠API and
C Extensions Native Project Zero interface
Extensions code
⢠Extension language choice opaque to PHP script
PZ Extensions
⢠Java Platform Bridge
⢠Debug using via DBGp using Eclipse with PDT
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 9
10. XAPI-J example
Extend PHP using Java Platform
@XAPIExtension(quot;BigDecimalquot;)
public class BigDecimalExt extends ExtensionBaseImpl {
@XAPIFunction(quot;add_bigdecimalquot;)
public void add(RuntimeContext ctxt) {
RuntimeServices rts = getRuntimeServices();
InvocationService inv =
rts.getInvocationService();
Object[] args =
inv.parseArguments(ctxt, quot;ssquot;, false);
BigDecimal arg1 = new BigDecimal((
( XAPIString) args[0]).getString());
BigDecimal arg2 = new BigDecimal((
( XAPIString) args[1]).getString());
BigDecimal result = arg1.add(arg2);
ctxt.setReturnValue(result.toString());
} Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 10
11. Java Platform Bridge
Easy access to Java Classes from PHP
<?php
$date = new Java(quot;java.util.Datequot;, 70, 9, 4);
var_dump($date->toString());
$map = new Java(quot;java.util.HashMapquot;);
$map->put(quot;titlequot;, quot;Java Bridge!quot;);
$map->put(quot;whenquot;, $date);
echo $map->get(quot;whenquot;)->toString().quot;nquot;;
echo $map->get(quot;titlequot;).quot;nquot;;
$array = array(1,2,3,4,5);
$map->put(quot;stuffquot;, $array); // PHP array converted to
Java Map
var_dump($map->get(quot;stuffquot;)).quot;nquot;;
?>
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 11
12. Agenda
Whys and Whats of PHP on the Java Virtual Machine
software
How we mix PHP, Java platform and Groovy
Demonstration of PHP and Java Platform Interaction
ProjectZero Community
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 12
13. Virtualized Directories
Facilitate Application Composition
Resources searched across application and
dependencies.
Apps behave as if directories merged.
Applies to all script directories.
⢠/public /app/resources, /app/scripts, /app/views etc.
First-one-wins precedence.
⢠Order based on dependency order in ivy files.
⢠Default files searched within each directory first:
⢠{my application}/index.php
⢠{my application}/index.html
⢠{dependency1}/index.php
⢠{dependency1}/index.html
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 13
14. REST Services
Made easy
Zero provides a really simple way to create REST
services
Convention for create/retrieve/update/delete operations
(CRUD)
⢠You can also list the members in the collection.
HTTP Method URI Description
GET /people List members
POST /people Create member
GET /people/1 Retrieve member
PUT /people/1 Update member
DELETE /people/1 Delete member
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 14
15. REST Services in WebSphere sMash
Each REST service is implemented by a script (called a handler)
Scripts live in the directory: <apphome>/app/resources
Services are accessed using a standard URL convention:
â˘/resources/<collection name>[/member[/<path
info>]]
HTTP requests mapped to handler methods as follows:
Resource GET PUT POST DELETE
Collection list putCollection create deleteCollecti
on
/people
Member retrieve update postMember delete
/people/1
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 15
17. Events
Promote Loose Coupling
All behaviour in the system is modelled as a set of events.
⢠Events are programming language agnostic
Fired by an application using fire_event().
fire_event('my_event', array(âdata'=>'foobar'));
Event handlers are defined in the Zero configuration file:
/config/handlers += {
quot;eventsquot; : my_event,
quot;handlerquot; : test.php
}
Request Processing events
⢠requestBegin, secure, GET, PUT, POST, DELETE, log, requestEnd
Application specific events
⢠Fired by your application
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 17
18. Global Context
Event handlers are stateless
⢠interesting applications contain state
GC provides access/management of application state
⢠It is NOT persistent. Persistent data goes into the database
Conceptually a map of data
Divided into a set of zones with different data lifecycles
Understands and provides intelligent access to certain
data types
Externalizes state from the application logic
⢠Enables clustering and scaling to be added transparently
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 18
19. Global Content Zones
Divided into zones representing different data lifecycles
Zone Scope/Visibility Lifecycle
Config All requests all users. Loaded from config
files.
Application All requests for all users of the Life of the application,
application but not âpersistentâ
User All request for a particular user For first access until
(HTTP Session equivalent) user times out
Request All handlers along the path of a For the duration of a
single request single request
Event All handlers for a single event The duration of a single
event
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 19
20. Versioning Dependencies
Modules are the building blocks of an application
A module is simply a collection of files packaged
together
⢠Includes a module name, version and author details
An application declares the modules it depends on
Versioning ensures applications donât break!
⢠Specific versions can be set (v1.1.34)
⢠Versions upwards from a particular release (v1.0+)
⢠Ranges of acceptable versions (v1.0 â v1.5)
Remote catalog servers at PZ.net and maven2
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 20
21. Deploying Applications
The Application is the server
Java VM
Web server
Application Code
Language runtimes
Hundreds of applications per box
Applications started on demand
⢠inetd style
Applications isolation
Quality of service and management built in
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 21
22. Built in development tooling
Browser-Based Development IDE
Built as a sMash application
Provides full development lifecycle for
Zero applications
⢠Create, Edit, Test
Provides Visual Editors for Activities and
Web Page construction
⢠Including a DOJO-enabled page editor
Basic Eclipse-based tooling also available if
required
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 22
23. Activities
Let Developers Visually âMash-upâ Services and Feeds
Compose applications by âwiringâ together
REST services
Visually or programmatically combine
existing feeds and services that enrich,
sort, and filter data in a pipeline
Configure templates to alter pipeline routes,
log events along the pipeline
Numerous built-in activities, including
⢠Get Feed, Call Service, Aggregate, Sort, Transform,
Filter, Send Mail, XSLT, Conditionals, Loops
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 23
24. Installing WebSphere sMash
Eclipse CLI / Browser IDE
Get JavaTM 1.5(+) JDK
Get PHP Development Tools (PDT)
Download installer (<800K)
All-in-one eclipse package
Install Zero using the Eclipse update manager Libraries fetched as needed.
Links and walkthrough on www.projectzero.org
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 24
25. Agenda
Whys and Whats of PHP on the Java Virtual Machine
software
How we mix PHP, Java platform and Groovy
Demonstration of PHP and Java Platform Interaction.
ProjectZero Community
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 25
26. Demo: Integration with SugarCRM
Scenario:
Scheduling meetings requires
co-ordination across the
business
Solution:
WebSphere sMash workflow
triggered from SugarCRM
PHP-Java Platform
Interoperability
⢠The best of both worlds
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 26
28. Agenda
Whys and Whats of PHP on the Java Virtual Machine
software
How we mix PHP, Java platform and Groovy
Demonstration of PHP and Java Platform Interaction
ProjectZero Community
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 28
29. Community Driven Commercial
Development
Evolve the core platform based on developer feedback
Commercial development using a transparent development process
Enabled via an external web site providing:
http://www.projectzero.org
A focal point for all sMash development activities
Expose the IBMÂŽ development process to the
external developer community
All design decisions are discussed and
communicated via external forums
Registered users can post comments and feedback
to the forums
Frictionless download of latest code and
documentation
Registration not required for binary downloads
Latest builds immediately available to developers
Source code can be viewed by registered users
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 29
30. Site Contents
Content
⢠Documentation
⢠Project information
⢠Roadmaps
⢠Design documents
⢠Demos and Samples
⢠iCal calendar
⢠Future plans
Forum for interactive discussion
⢠Help and Feedback for questions from users
⢠Developer Alerts to notify users of new features and breaking changes
⢠Zero Development for publicly accessible discussion amongst the Zero development team
⢠3554 Posts on 828 Topics to date
Blogs
⢠Development blog with interesting commentary, demos, and opinion
⢠News blog for project announcements
Binary Downloads (257,738 and countingâŚ)
Bug Tracking System (Bugzilla)
Source code (Subversion)
Š 2008 IBM Corporation 3
2008 JavaOneSM Conference | java.sun.com/javaone | 30
31. Features of sMash we have not covered
today
File Serving
Error Handling
View Rendering
Logging, Tracing, Debugging
Client Programming with the Dojo Ajax Framework
Security
Nested resources
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 31
32. Summary
Project Zero is incubating technologies to build web
applications in WebSphere sMash
⢠Simply!
WebSphere sMash contains a PHP runtime which runs on
a JVM software
WebSphere sMash enables same process interoperability
between PHP, Java platform and Groovy
Š 2008 IBM Corporation
2008 JavaOneSM Conference | java.sun.com/javaone | 32