SlideShare ist ein Scribd-Unternehmen logo
1 von 35
High Performance XQuery
Processing in PHP with Zorba




                               Vikram Vaswani
                               November 2012
Vikram Vaswani
Founder, Melonfire
●   Product design and implementation with open source technologies
●   20+ products launched for customers worldwide
Author and active PHP community participant
●   7 books for McGraw-Hill USA
●   250+ tutorials for IBM dW, Zend Developer Zone and others

More information at http://vikram-vaswani.in
XML Support in PHP
●   XML processing: SimpleXML and XMLReader
●   XML transformation: XSLT and XML-DAS
●   Event-based parsing: SAX
●   Tree-based parsing: DOM
●   Serialization: WDDX
●   Dynamic documents: XMLWriter
What's Missing?
Introducing Zorba
●   General purpose XQuery processor for PHP 5.3+
●   Supports XQuery v1.0 and related specifications
●   Available for Windows, Linux, and Mac OS X
●   Open source; Apache 2.0 License
●   Project supported by FLWOR Foundation and
    Oracle.
Supported XML Technologies
●   XPath
●   XQuery v1.0 and v3.0
●   XQuery Scripting
●   Xquery Data Definition
●   XPath Full-Text 1.0
●   XSLT 1.0
●   XqueryX (limited)
PHP Installation
●   Linux and MacOS X
    ●   Libxml2: http://xmlsoft.org/
    ●   Iconv: http://www.gnu.org/software/libiconv/
    ●   libUUID: http://linux.die.net/man/3/libuuid
    ●   ICU (C version): http://www.icu-project.org/
    ●   Xerces (C version): http://xerces.apache.org/xerces-c/
    ●   GCC and related make/cmake utilities
●   Windows
    ●   https://launchpad.net/zorba/+download
●   API Wrapper
    ●   http://zorba.s3.amazonaws.com/ZorbaPHP.zip
PHP Installation
●   Linux and MacOS X
    ●   Libxml2: http://xmlsoft.org/
    ●   Iconv: http://www.gnu.org/software/libiconv/
    ●   libUUID: http://linux.die.net/man/3/libuuid
    ●   ICU (C version): http://www.icu-project.org/
    ●   Xerces (C version): http://xerces.apache.org/xerces-c/
    ●   GCC and related make/cmake utilities
●   Windows
    ●   https://launchpad.net/zorba/+download
●   API Wrapper
    ●   http://zorba.s3.amazonaws.com/ZorbaPHP.zip
Basic Usage
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
try {
    $queryStr = <<<END
    let $message := 'She sells sea shells by the sea shore'
    return
    <result>{$message}</result>
END;
    $query = $zorba->importQuery($queryStr);
    $result = $zorba->execute();
    echo $result;
} catch (Exception $e) {
    die('ERROR:' . $e->getMessage());
}
                                    Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                            http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Basic Usage
Usage Examples
Arithmetic Operators
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<<END
  declare variable $x := 30;
  declare variable $y := 12;
  let $r := $x + $y
  return
  <result> {$r} </result>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                             Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                     http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Sequences
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<<END
 let $dolls := ('Echo', 'Victor', 'Sierra', 'November', 'Alpha')
 return
 <results>
 {
     for $doll in $dolls
     return
     <name>{$doll}</name>
 }
 </results>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                    Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                            http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
String Functions
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<<END
  let $dolls := ('Echo', 'Victor', 'Sierra', 'November', 'Alpha')
  return
  <results>
  {string-join($dolls, ', ')}
  </results>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();




                                  Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                          http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Math Functions
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<<END
 let $set := (1 to 20)
 return
 <results>
 {
       for $i in $set
       where ($i mod 2 eq 0)
       return
       <value> {$i} </value>
 }
 </results>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();

                                           Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                   http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Data Filtering
(XML source)
<?xml version="1.0"?>
<data>
  <record>
    <code>ABW</code>
    <name>Aruba</name>
    <continent>North America</continent>
    <year></year>
    <population>103000</population>
    <gnp>828.00</gnp>
    <capital>
        <name>Oranjestad</name>
        <population>29034</population>
    </capital>
  </record>
  ...
</data>                                  Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                 http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Data Filtering (Simple)
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$dm = $zorba->getXmlDataManager();
$dm->loadDocument('data.xml', file_get_contents('data.xml'));
$queryStr = <<< END
 for $record in doc('data.xml')//record
 let $name := $record/name/text()
 let $code := $record/code/text()
 return
 <name code="{$code}">{$name}</name>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                  Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                          http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Data Filtering (Complex)
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
dm = $zorba->getXmlDataManager();
$dm->loadDocument('data.xml', file_get_contents('data.xml'));
$queryStr = <<< END
 for $record in doc('data.xml')//record
 let $name := $record/name/text()
 let $code := $record/code/text()
 let $population := $record/population/text()
 where contains($record/continent/text(), 'Europe')
 where (xs:integer($population) gt 1000000)
 order by $population descending
 return
 <name code="{$code}" population="{$population}">{$name}</name>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                            Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                    http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Node Manipulation
(XML source, before)
<?xml version='1.0'?>
<heroes>
 <hero>
   <name>Spiderman</name>
   <alterego>Peter Parker</alterego>
 </hero>
 <hero>
   <name>Superman</name>
   <alterego>Clark Kent</alterego>
 </hero>
 <hero>
   <name>The Flash</name>
   <alterego>Wally West</alterego>
 </hero>
</heroes>
                                       Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                               http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Node Manipulation
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$dm = $zorba->getXmlDataManager();
$dm->loadDocument('heroes.xml', file_get_contents('heroes.xml'));
$queryStr = <<< END
 delete node doc('heroes.xml')//heroes/hero[last()],
 replace node doc('heroes.xml')//heroes/hero[last()]
 with
 <hero>
       <name>The Incredible Hulk</name>
       <alterego>Bruce Banner</alterego>
 </hero>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                           Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                   http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Node Manipulation
(XML source, after)
<?xml version="1.0" encoding="UTF-8"?>
<heroes>
 <hero>
    <name>Spiderman</name>
    <alterego>Peter Parker</alterego>
 </hero>
 <hero>
    <name>Superman</name>
    <alterego>Clark Kent</alterego>
 </hero>
 <hero>
    <name>The Incredible Hulk</name>
    <alterego>Bruce Banner</alterego>
 </hero>
</heroes>
                                        Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
REST Parser
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<< END
  import module namespace zorba-rest =
    "http://www.zorba-xquery.com/zorba/rest-functions";
  for $post in
    zorba-rest:get("http://user:pass@api.del.icio.us/v1/posts/recent")//posts/post
  where contains($post/@tag, 'book')
  return
  <result>
    <href> {string($post/@href)} </href>
    <description> {string($post/@description)} </description>
    <tags> {string($post/@tag)} </tags>
  </result>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();

                                            Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                                    http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
REST Parser
(After)
<?xml version="1.0" encoding="UTF-8"?>

<result>

 <href>http://www.everythingphpmysql.com/</href>

 <description>How to do Everything with PHP & MySQL - Vikram Vaswani</description>

 <tags>book development php mysql web beginner</tags>

</result>

<result>

 <href>http://www.mysql-tcr.com/</href>

 <description>MySQL: The Complete Reference - Vikram Vaswani</description>

 <tags>mysql php book</tags>

</result>
JSON Parser
(JSON source)
{
    "books": [{
     "title":"Phantom Prey",
     "author":"John Sandford",
     "price":"7.99"
    }, {
     "title":"A Most Wanted Man",
     "author":"John le Carre",
     "price":"8.99"
    },{
     "title":"Beach Babylon",
     "author":"Imogen Edward-Jones",
     "price":"12.99"
    }]
}
                                       Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                               http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
JSON Parser
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<< END
 import module namespace json =
         "http://www.zorba-xquery.com/zorba/json-functions";
       let $x := json:parse('{$json}')
       for $i in $x//item
       where (xs:decimal($i/pair[@name='price']/text()) lt 10.00)
       return
       <result> {$i/pair[@name='title']/text()} </result>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                    Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                            http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
JSON Parser
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();
$queryStr = <<< END
 import module namespace json =
         "http://www.zorba-xquery.com/zorba/json-functions";
       let $x := json:parse('{$json}')
       for $i in $x//item
       where (xs:decimal($i/pair[@name='price']/text()) lt 10.00)
       return
       <result> {$i/pair[@name='title']/text()} </result>
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();
                                    Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba"
                                                            http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
Performance
Scenario
●   Data
    ●   1 day of forecast data in XML format: 727MB
●   Workflow
    ●   Process data for a specific site
    ●   Send selected temperatures to clients
    ●   Display chart




                                    Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
SimpleXML
<?php
$siteId = 3;


$forecasts = simplexml_load_file('forecasts.xml');
$forecasts = $forecasts->xpath(
    "/forecast-list/forecast[@site-id='$siteId']");


foreach($forecasts as$forecast) {
    $time = $forecast->xpath("@time-step");
    $value = $forecast->xpath(
      "//weather-elements/weather-element"
      ."[@name = 'ScreenTemperature']/text()");
    echo "<temperature time='" . $time[0] ."'value='" = . $value[0] . "' />n";
}
?>

                                             Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                         http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
Zorba
<?php
require_once 'Zorba/XQueryProcessor.php';
$zorba = new XQueryProcessor();


$queryStr = <<<END
  for $forecast inz:parse-xml(file:read-text("forecasts.xml"),
    <opt:options>
    <opt:parseExternalParsedEntity opt:skipRootNodes="1"/>
    </opt:options>)
  where $forecast/@site-id = "3"
  let $time:= string($forecast/@time-step)
  let $value:= $forecast/weather-elements/weather-element
    [@name = 'ScreenTemperature']/text()
  return
  <temperaturetime="{$time}" value="{$value}" />
END;
$query = $zorba->importQuery($queryStr);
echo $zorba->execute();

                                                 Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                             http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
Results

                            10000

                                      9000
                            9000

                            8000
  Memory Consumption (MB)




                            7000

                            6000

                            5000

                            4000

                            3000

                            2000

                            1000

                                                                                                      19
                               0
                                    SimpleXML                                                       Zorba
                                                   PHP Extension


                                                    Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                                http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
AWS Libraries

                10000

                9000    8589

                8000

                7000
Lines of Code




                6000

                5000
                                                                                                                              Java
                4000                                                                                                          XQuery

                                              2905
                3000
                                                                                      2309
                2000                1469
                1000                                       572                                       455
                   0
                               S3                SimpleDB                                    SNS

                                           AWS Libraries




                                                     Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry"
                                                 http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
Resources
●   Usage docs: zorba-xquery.com/html/documentation
●   Live demo: zorba-xquery.com/html/demo
●   Source code: code.launchpad.net/~zorba-
    coders/zorba/trunk
●   Modules: zorba-xquery.com/html/modules
●   Toolkit: xqdt.org
●   Forums: zorba-users [at] googlegroups [dot] com
●   News: zorba-xquery.com/html/blog
●   Twitter: @wcandillon
Questions?
Contact Information
Email:
●   vikram-vaswani.in/contact
Web:
●   www.melonfire.com
●   vikram-vaswani.in
Social networks:
●   plus.google.com/100028886433648406825
●   twitter.com/melonfire

Weitere ähnliche Inhalte

Was ist angesagt?

KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天tblanlan
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)Night Sailer
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrideugenio pombi
 
The state of your own hypertext preprocessor
The state of your own hypertext preprocessorThe state of your own hypertext preprocessor
The state of your own hypertext preprocessorAlessandro Nadalin
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserHoward Lewis Ship
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on AndroidSven Haiges
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEBHoward Lewis Ship
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIsRemy Sharp
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
Immutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS LambdaImmutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS LambdaAOE
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchPedro Franceschi
 
MongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksMongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksScott Hernandez
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to NodejsGabriele Lana
 
Node.js in action
Node.js in actionNode.js in action
Node.js in actionSimon Su
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuerydeimos
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011CodeIgniter Conference
 

Was ist angesagt? (19)

KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天KISSY 的昨天、今天与明天
KISSY 的昨天、今天与明天
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
The state of your own hypertext preprocessor
The state of your own hypertext preprocessorThe state of your own hypertext preprocessor
The state of your own hypertext preprocessor
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Testing Web Applications with GEB
Testing Web Applications with GEBTesting Web Applications with GEB
Testing Web Applications with GEB
 
HTML5 JavaScript APIs
HTML5 JavaScript APIsHTML5 JavaScript APIs
HTML5 JavaScript APIs
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Immutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS LambdaImmutable Deployments with AWS CloudFormation and AWS Lambda
Immutable Deployments with AWS CloudFormation and AWS Lambda
 
Fazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearchFazendo mágica com ElasticSearch
Fazendo mágica com ElasticSearch
 
Fatc
FatcFatc
Fatc
 
MongoDB: tips, trick and hacks
MongoDB: tips, trick and hacksMongoDB: tips, trick and hacks
MongoDB: tips, trick and hacks
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Introduction to Nodejs
Introduction to NodejsIntroduction to Nodejs
Introduction to Nodejs
 
Scala active record
Scala active recordScala active record
Scala active record
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
 
Remy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQueryRemy Sharp The DOM scripting toolkit jQuery
Remy Sharp The DOM scripting toolkit jQuery
 
Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011Bottom to Top Stack Optimization - CICON2011
Bottom to Top Stack Optimization - CICON2011
 

Ähnlich wie High Performance XQuery Processing in PHP with Zorba

[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With RailsBoris Nadion
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsMykyta Protsenko
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)James Titcumb
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
Express Presentation
Express PresentationExpress Presentation
Express Presentationaaronheckmann
 
apidays LIVE Australia - Building distributed systems on the shoulders of gia...
apidays LIVE Australia - Building distributed systems on the shoulders of gia...apidays LIVE Australia - Building distributed systems on the shoulders of gia...
apidays LIVE Australia - Building distributed systems on the shoulders of gia...apidays
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetAchieve Internet
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajaxs_pradeep
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionSysdig
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJSAaronius
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applicationsTom Croucher
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.jsYoann Gotthilf
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS IntroNgoc Dao
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...Willian Molinari
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 

Ähnlich wie High Performance XQuery Processing in PHP with Zorba (20)

[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Sprockets
SprocketsSprockets
Sprockets
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With Rails
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and Ops
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
Express Presentation
Express PresentationExpress Presentation
Express Presentation
 
apidays LIVE Australia - Building distributed systems on the shoulders of gia...
apidays LIVE Australia - Building distributed systems on the shoulders of gia...apidays LIVE Australia - Building distributed systems on the shoulders of gia...
apidays LIVE Australia - Building distributed systems on the shoulders of gia...
 
WCLV13 JavaScript
WCLV13 JavaScriptWCLV13 JavaScript
WCLV13 JavaScript
 
Harmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and PuppetHarmonious Development: Via Vagrant and Puppet
Harmonious Development: Via Vagrant and Puppet
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
Wordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccionWordpress y Docker, de desarrollo a produccion
Wordpress y Docker, de desarrollo a produccion
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
Writing robust Node.js applications
Writing robust Node.js applicationsWriting robust Node.js applications
Writing robust Node.js applications
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Introduction to REST API with Node.js
Introduction to REST API with Node.jsIntroduction to REST API with Node.js
Introduction to REST API with Node.js
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
How we used ruby to build locaweb's cloud (http://presentations.pothix.com/ru...
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 

Kürzlich hochgeladen

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Kürzlich hochgeladen (20)

Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

High Performance XQuery Processing in PHP with Zorba

  • 1. High Performance XQuery Processing in PHP with Zorba Vikram Vaswani November 2012
  • 2. Vikram Vaswani Founder, Melonfire ● Product design and implementation with open source technologies ● 20+ products launched for customers worldwide Author and active PHP community participant ● 7 books for McGraw-Hill USA ● 250+ tutorials for IBM dW, Zend Developer Zone and others More information at http://vikram-vaswani.in
  • 3. XML Support in PHP ● XML processing: SimpleXML and XMLReader ● XML transformation: XSLT and XML-DAS ● Event-based parsing: SAX ● Tree-based parsing: DOM ● Serialization: WDDX ● Dynamic documents: XMLWriter
  • 5. Introducing Zorba ● General purpose XQuery processor for PHP 5.3+ ● Supports XQuery v1.0 and related specifications ● Available for Windows, Linux, and Mac OS X ● Open source; Apache 2.0 License ● Project supported by FLWOR Foundation and Oracle.
  • 6. Supported XML Technologies ● XPath ● XQuery v1.0 and v3.0 ● XQuery Scripting ● Xquery Data Definition ● XPath Full-Text 1.0 ● XSLT 1.0 ● XqueryX (limited)
  • 7. PHP Installation ● Linux and MacOS X ● Libxml2: http://xmlsoft.org/ ● Iconv: http://www.gnu.org/software/libiconv/ ● libUUID: http://linux.die.net/man/3/libuuid ● ICU (C version): http://www.icu-project.org/ ● Xerces (C version): http://xerces.apache.org/xerces-c/ ● GCC and related make/cmake utilities ● Windows ● https://launchpad.net/zorba/+download ● API Wrapper ● http://zorba.s3.amazonaws.com/ZorbaPHP.zip
  • 8. PHP Installation ● Linux and MacOS X ● Libxml2: http://xmlsoft.org/ ● Iconv: http://www.gnu.org/software/libiconv/ ● libUUID: http://linux.die.net/man/3/libuuid ● ICU (C version): http://www.icu-project.org/ ● Xerces (C version): http://xerces.apache.org/xerces-c/ ● GCC and related make/cmake utilities ● Windows ● https://launchpad.net/zorba/+download ● API Wrapper ● http://zorba.s3.amazonaws.com/ZorbaPHP.zip
  • 9. Basic Usage <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); try { $queryStr = <<<END let $message := 'She sells sea shells by the sea shore' return <result>{$message}</result> END; $query = $zorba->importQuery($queryStr); $result = $zorba->execute(); echo $result; } catch (Exception $e) { die('ERROR:' . $e->getMessage()); } Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 12. Arithmetic Operators <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END declare variable $x := 30; declare variable $y := 12; let $r := $x + $y return <result> {$r} </result> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 13. Sequences <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END let $dolls := ('Echo', 'Victor', 'Sierra', 'November', 'Alpha') return <results> { for $doll in $dolls return <name>{$doll}</name> } </results> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 14. String Functions <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END let $dolls := ('Echo', 'Victor', 'Sierra', 'November', 'Alpha') return <results> {string-join($dolls, ', ')} </results> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 15. Math Functions <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END let $set := (1 to 20) return <results> { for $i in $set where ($i mod 2 eq 0) return <value> {$i} </value> } </results> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 16. Data Filtering (XML source) <?xml version="1.0"?> <data> <record> <code>ABW</code> <name>Aruba</name> <continent>North America</continent> <year></year> <population>103000</population> <gnp>828.00</gnp> <capital> <name>Oranjestad</name> <population>29034</population> </capital> </record> ... </data> Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 17. Data Filtering (Simple) <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $dm = $zorba->getXmlDataManager(); $dm->loadDocument('data.xml', file_get_contents('data.xml')); $queryStr = <<< END for $record in doc('data.xml')//record let $name := $record/name/text() let $code := $record/code/text() return <name code="{$code}">{$name}</name> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 18. Data Filtering (Complex) <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); dm = $zorba->getXmlDataManager(); $dm->loadDocument('data.xml', file_get_contents('data.xml')); $queryStr = <<< END for $record in doc('data.xml')//record let $name := $record/name/text() let $code := $record/code/text() let $population := $record/population/text() where contains($record/continent/text(), 'Europe') where (xs:integer($population) gt 1000000) order by $population descending return <name code="{$code}" population="{$population}">{$name}</name> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 19. Node Manipulation (XML source, before) <?xml version='1.0'?> <heroes> <hero> <name>Spiderman</name> <alterego>Peter Parker</alterego> </hero> <hero> <name>Superman</name> <alterego>Clark Kent</alterego> </hero> <hero> <name>The Flash</name> <alterego>Wally West</alterego> </hero> </heroes> Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 20. Node Manipulation <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $dm = $zorba->getXmlDataManager(); $dm->loadDocument('heroes.xml', file_get_contents('heroes.xml')); $queryStr = <<< END delete node doc('heroes.xml')//heroes/hero[last()], replace node doc('heroes.xml')//heroes/hero[last()] with <hero> <name>The Incredible Hulk</name> <alterego>Bruce Banner</alterego> </hero> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 21. Node Manipulation (XML source, after) <?xml version="1.0" encoding="UTF-8"?> <heroes> <hero> <name>Spiderman</name> <alterego>Peter Parker</alterego> </hero> <hero> <name>Superman</name> <alterego>Clark Kent</alterego> </hero> <hero> <name>The Incredible Hulk</name> <alterego>Bruce Banner</alterego> </hero> </heroes> Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 22. REST Parser <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<< END import module namespace zorba-rest = "http://www.zorba-xquery.com/zorba/rest-functions"; for $post in zorba-rest:get("http://user:pass@api.del.icio.us/v1/posts/recent")//posts/post where contains($post/@tag, 'book') return <result> <href> {string($post/@href)} </href> <description> {string($post/@description)} </description> <tags> {string($post/@tag)} </tags> </result> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 23. REST Parser (After) <?xml version="1.0" encoding="UTF-8"?> <result> <href>http://www.everythingphpmysql.com/</href> <description>How to do Everything with PHP & MySQL - Vikram Vaswani</description> <tags>book development php mysql web beginner</tags> </result> <result> <href>http://www.mysql-tcr.com/</href> <description>MySQL: The Complete Reference - Vikram Vaswani</description> <tags>mysql php book</tags> </result>
  • 24. JSON Parser (JSON source) { "books": [{ "title":"Phantom Prey", "author":"John Sandford", "price":"7.99" }, { "title":"A Most Wanted Man", "author":"John le Carre", "price":"8.99" },{ "title":"Beach Babylon", "author":"Imogen Edward-Jones", "price":"12.99" }] } Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 25. JSON Parser <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<< END import module namespace json = "http://www.zorba-xquery.com/zorba/json-functions"; let $x := json:parse('{$json}') for $i in $x//item where (xs:decimal($i/pair[@name='price']/text()) lt 10.00) return <result> {$i/pair[@name='title']/text()} </result> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 26. JSON Parser <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<< END import module namespace json = "http://www.zorba-xquery.com/zorba/json-functions"; let $x := json:parse('{$json}') for $i in $x//item where (xs:decimal($i/pair[@name='price']/text()) lt 10.00) return <result> {$i/pair[@name='title']/text()} </result> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: Vikram Vaswani, " Building XQue ry-po we re d applicatio ns with PHP and Zo rba" http: //www. ibm. co m/de ve lo pe rwo rks/library/x-zo rba/inde x. html
  • 28. Scenario ● Data ● 1 day of forecast data in XML format: 727MB ● Workflow ● Process data for a specific site ● Send selected temperatures to clients ● Display chart Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 29. SimpleXML <?php $siteId = 3; $forecasts = simplexml_load_file('forecasts.xml'); $forecasts = $forecasts->xpath( "/forecast-list/forecast[@site-id='$siteId']"); foreach($forecasts as$forecast) { $time = $forecast->xpath("@time-step"); $value = $forecast->xpath( "//weather-elements/weather-element" ."[@name = 'ScreenTemperature']/text()"); echo "<temperature time='" . $time[0] ."'value='" = . $value[0] . "' />n"; } ?> Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 30. Zorba <?php require_once 'Zorba/XQueryProcessor.php'; $zorba = new XQueryProcessor(); $queryStr = <<<END for $forecast inz:parse-xml(file:read-text("forecasts.xml"), <opt:options> <opt:parseExternalParsedEntity opt:skipRootNodes="1"/> </opt:options>) where $forecast/@site-id = "3" let $time:= string($forecast/@time-step) let $value:= $forecast/weather-elements/weather-element [@name = 'ScreenTemperature']/text() return <temperaturetime="{$time}" value="{$value}" /> END; $query = $zorba->importQuery($queryStr); echo $zorba->execute(); Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 31. Results 10000 9000 9000 8000 Memory Consumption (MB) 7000 6000 5000 4000 3000 2000 1000 19 0 SimpleXML Zorba PHP Extension Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 32. AWS Libraries 10000 9000 8589 8000 7000 Lines of Code 6000 5000 Java 4000 XQuery 2905 3000 2309 2000 1469 1000 572 455 0 S3 SimpleDB SNS AWS Libraries Cre dit: W illiam Candillo n, " Cutting Edg e Data Pro ce ssing with PHP & XQue ry" http: //www. slide share . ne t/wcandillo n/cutting -e dg e -data-pro ce ssing -with-php-xque ry
  • 33. Resources ● Usage docs: zorba-xquery.com/html/documentation ● Live demo: zorba-xquery.com/html/demo ● Source code: code.launchpad.net/~zorba- coders/zorba/trunk ● Modules: zorba-xquery.com/html/modules ● Toolkit: xqdt.org ● Forums: zorba-users [at] googlegroups [dot] com ● News: zorba-xquery.com/html/blog ● Twitter: @wcandillon
  • 35. Contact Information Email: ● vikram-vaswani.in/contact Web: ● www.melonfire.com ● vikram-vaswani.in Social networks: ● plus.google.com/100028886433648406825 ● twitter.com/melonfire