Vous êtes sur la page 1sur 28

®

An Introduction to IBM WebSphere


sMash for PHP Programmers

Jonathan Lawrence & Robin Fernandes


Software Developers, WebSphere Development, IBM
projectzero.org

© 2009 IBM Corporation


Agenda

Overview of WebSphere sMash


Simple sMash demonstration
PHP in sMash
PHP sMash demonstration
Summary and Questions

2 © 2009 IBM Corporation


What is WebSphere sMash?

 WebSphere sMash is a new Agile Web


Application Platform
Exploiting Dynamic Scripting Languages
Optimized for producing...
 REST-based Services
 Integration Applications
 Mash-ups
 Rich Web Interfaces
Architected for...
 Speed, Simplicity & Agility

3 © 2009 IBM Corporation


What is WebSphere sMash?
 JavaTM Virtual Machine based runtime supporting PHP
and Groovy.
NOT a Java EE environment

 Targeted at Script developers


Not for producing Java code.

 A Commercial Project
With development done in the open and limited no-cost use.
Download for free at http://projectzero.org.

 A Full Stack Runtime


With a HTTP server, module system and simple IDE built in.

4 © 2009 IBM Corporation


WebSphere sMash for the application long tail
For business department and mid-market customers looking for rapidly
developed agile applications, short implementation cycles and ways to
easily reuse existing investments.

Application Server

Strategic, long-lived applications

Time to value is more important than


enduring value
Usage

Java
Enterprise
Edition

Dynamic Scripting
Number of Applications
5 © 2009 IBM Corporation
Accelerate business and IT alignment

Speed Dynamic scripting languages


Templates & pre-built services

Simplicity No-charge, robust browser & Eclipse based tooling


Simply create rich Web 2.0 interfaces

Application “is” the server


Agility
Clean, short-lived runtime

6 © 2009 IBM Corporation


Speed
WebSphere sMash is easy for developers to access, learn, and use

 Dynamic Scripting
PHP
Groovy (JavaTM Language Syntax)
 Effortless creation of RESTful
Services
 Simple event-based execution
environment
 State externalized into a shared
memory space (Global Context)
 Repository of pre-built templates,
services, libraries, and connectors

7 © 2009 IBM Corporation


Simplicity
WebSphere sMash makes it simple to “mash-up” services and feeds

 Free browser-based and Eclipse-


based tools provide a simple
environment for constructing
applications based on dynamic
scripting languages.

 Visual tooling makes it simple to


create complex, rich, dynamic, data-
centric Web 2.0 user interfaces based
on Ajax.

 sMash is a full stack runtime – JEE


web container not required.

8 © 2009 IBM Corporation


Agility
WebSphere sMash focuses on deploying applications, not servers

 Cost effective execution


Memory and disk footprint minimal.
Many apps possible per box.

 Clean execution
Applications are isolated and
secured from each other
Periodic re-cycling of applications
reduces failures

9 © 2009 IBM Corporation


Dynamic Scripting

 WebSphere sMash is a dynamic scripting platform


 Application Logic is created in one of two scripting
languages
 PHP (for the 3 Million existing PHP programmers)
 Groovy (for people that prefer JavaTM)

 Java is positioned as the “system” language


 Mostly used to implement system extensions and application
libraries
 Entire applications can be written in Java, if desired
 Requires more configuration

10 © 2009 IBM Corporation


Application-centric Runtime

 WebSphere sMash is an application-centric runtime


You create an application and run it
You do not package an application and deploy it to a multi-
application server
Each application runs in its own process (JVM)
Runtime is designed to be short lived

 WebSphere sMash is a full stack runtime


Everything needed to run the application is provided
 Including the HTTP stack
No external proxy or web server is required
 Except for clustering and multi-app routing

11 © 2009 IBM Corporation


Modular Architecture
 WebSphere sMash applications are based on a very small core

 Additional features provided in downloadable modules


 Applications declare dependencies using Apache Ivy
 A package management system manages your dependencies,
including facilities to:
 share dependencies on a machine
 load missing dependencies from the network on demand
 manage updates to dependencies

12 © 2009 IBM Corporation


Available Modules

 There are approximately 65 modules available currently


 Modules provide function in many categories
Data Formats (JSON, ATOM, RSS, XML)
Data Access
Resource Modeling
Security / Content Filtering
Activity Flows
Services
 Amazon ECS, Flickr, Weather, etc
Utilities (such as HTML parsing)
Management Tools
Development Tooling
Reliable Transport Engine for Messaging Interactions

13 © 2009 IBM Corporation


Agenda

Overview of WebSphere sMash


Simple sMash demonstration
PHP in sMash
PHP sMash demonstration
Summary and Questions

14 © 2009 IBM Corporation


Agenda

Overview of WebSphere sMash


Simple sMash demonstration
PHP in sMash
PHP sMash demonstration
Summary and Questions

15 © 2009 IBM Corporation


WebSphere sMash PHP Support
PHP runtime built in JavaTM.

Compile PHP into Java bytecodes and run on a JVM.

Powerful blending of PHP and Java code.


Java and PHP code run in the same process
 No need for Inter-process communication.
Efficient calls between PHP, Java and Groovy
Pass data between PHP, Java and Groovy without copying
 Avoids serialising and passing data between processes.
Import Java classes as PHP Classes
 Easy access to the many Java libraries from PHP code.

16 © 2009 IBM Corporation


PHP in WebSphere sMash
• Runs PHP 5 scripts
Java Virtual Machine • Requires Java 5 SE or later.

HTTP server
• Extensibility via XAPI
• XAPI-C for C extensions from php.net
Zero Programming Model • XAPI-J for Java extensions, native libraries invoked
over JNI and Project Zero interface
• Extension language choice opaque to PHP script
Java- Bridge

JAR
JAR
PHP runtime • Java Bridge
TM
Groovy
Debug

JAR P8 Runtime runtime


Interpreter/Compiler
• Debug using via DBGp protocol using Eclipse with PDT
JAR

XAPI-J
XAPI-C
Java
C Extensions
Extensions

WebSphere sMash
PDT2

17 © 2009 IBM Corporation


Benefits of PHP in sMash.
 Develop quickly using the best tools for the job.
PHP code such as smarty, drupal, phpBB,
Java code such as Apache Lucene, POI and Eclipse BIRT

 Start simple using sMash tooling such as ZRM


Customise and extend using PHP scripts and snippets

 Build on a solid base.


PHP built on the Java VM at the heart of IBM’s enterprise software stack.
 Vast investment in JIT, Garbage Collector, RAS and tools.

 Enable agile teams to use Java and PHP skills.


Allow teams to use their full range of skills.
Integrate Java and PHP code seamlessly using the Java Bridge

18 © 2009 IBM Corporation


PHP – Java Bridge – Basic use
<?php
Access Java methods and
java_import("java.util.Date");
fields from PHP
$date = new Date(81, 9, 12);
echo $date . PHP_EOL;
// prints: Sun Oct 11 00:00:00 BST 1981

java_import("java.util.HashMap");
$map = new HashMap();
$map->put("stuff", array(1,2,3,4,5)); Types are automatically
var_dump($map->get("stuff")); converted at boundary of
// prints: array(5) { ... PHP runtime

<?php
Static methods and fields java_import("java.lang.System");
are accessible too echo System::currentTimeMillis();

try {
System::getProperty(FALSE);
Java exceptions can be } catch (JavaException $exception) {
caught and handled in PHP echo $exception->getMessage();
}

19 © 2009 IBM Corporation


Java Bridge – Extending Java in PHP

PHP classes can extend Java classes


<?php
java_import("java.io.File");

class SubFile extends File {


function SuperFile($path) {
parent::__construct($path);
}

function isThisCool() {
return TRUE; // Way cool
}
}

$file = new SubFile("/");


var_dump($file->isDirectory());
var_dump($file->isThisCool());

20 © 2009 IBM Corporation


PHP- Java Bridge – Iterators and Overloads
<?php
java_import("java.util.ArrayList");
Java iteration is bridged into PHP
$list = new ArrayList();
$list->add("Hello World!");
$list->add(FALSE);
$list->add(1234567890);

foreach ($list as $key => $value) {


echo "$key $value\n";
}

<?php
java_import("java.lang.String");
$signature = new JavaSignature(JAVA_INT);
var_dump(String::valueOf($signature, 1234567890));

Signatures provide explicit control for


overloaded methods

21 © 2009 IBM Corporation


Java Bridge – More features…
<?php
java_import("java.math.BigDecimal", NULL, FALSE, "My_BigDecimal");
$value = new My_BigDecimal("1.18E+10");
echo $value;

Import a Java class under a different


name to avoid clashes

<?php
java_import("java.lang.Comparable"); PHP reflection works on Java
echo(ReflectionClass::export("Comparable")); classes

<?php
java_import("java.io.File");
$file = new File("/home/robinf");

var_dump($file->Parent);
//equivalent to:
Java bean support provides field
var_dump($file->getParent());
access for get/set method calls

22 © 2009 IBM Corporation


Agenda

Overview of WebSphere sMash


Simple sMash demonstration
PHP in sMash
PHP sMash demonstration
Summary and Questions

23 © 2009 IBM Corporation


Agenda

Overview of WebSphere sMash


Simple sMash demonstration
PHP in sMash
PHP sMash demonstration
Summary and Questions

24 © 2009 IBM Corporation


Some PHP Applications that run on sMash

Forums Ajax
wiki
Debugging
FirePHP
CRM

Content Desktop
Management Virtualisation Blogging

25 © 2009 IBM Corporation


Features we didn’t cover
 Client Programming with the Dojo Framework
 Assemble Tooling
 Data APIs
 Security
 Eclipse-based tooling
 REST to SOAP adapter
 Reliable Messaging
 Error Handling
 Logging, Tracing, Debugging
…

26 © 2009 IBM Corporation


Project Zero – projectzero.org
Project Zero is the development and incubation community around
WebSphere sMash

Visit http://projectzero.org
 Download sMash for free
 View “Getting Started” guides
 Watch videos of sMash in action
 Access our source, bug tracker,
developer discussions…
 Chat with the community on the
forum

Come to our stand for more demos!


27 © 2009 IBM Corporation
Legal Notices
 Java and all Java-based trademarks and logos are trademarks of Sun
Microsystems, Inc. in the United States, other countries, or both.
 Microsoft, Windows, Windows NT, and the Windows logo are trademarks of
Microsoft Corporation in the United States, other countries, or both.
 Intel and Pentium are trademarks or registered trademark of Intel Corporation or
its subsidiaries in the United States and other countries.
 UNIX is a registered trademark of The Open Group in the United States and other
countries.
 Linux is a trademark of Linus Torvalds in the United States, other countries, or
both.
 Other company, product, or service names may be trademarks or service marks
of others.

28 © 2009 IBM Corporation

Vous aimerez peut-être aussi