1 harnessing web services with php geoff peters php vancouver conference jan. 23, 2004
TRANSCRIPT
1
Harnessing Web ServicesWith PHP
Geoff PetersPHP Vancouver Conference
Jan. 23, 2004
2
What are Web Services Emerging standards Allow service applications to be
accessible across the web to client (non-human) applications
Example: Incorporating a web-based mapping service into your pizza delivery application.
3
Pizza Application Example
MappingDatabase Internet
PizzaDelivery
Application
Web Services
Thanks, Web Services!
4
Some Uses of Web Services Business to Business (B2B)
communication Online storefronts Syndication of News Feeds
5
Examples of Web Services Amazon.com (Storefronts) Google.com (Google API) Microsoft (MSDN, Terraservice,
Mappoint, .NET Alerts) Bioinformatics (EMBL Nucleotide
Sequence Database, BQS) AllConsuming.Net Weblogs.com, Technorati.com, and
Alexa.com
6
Problem of Information Fragmentation Information is scattered in thousands
of different databases/resources Currently, each resource (or group)
must be manually accessed Growth of available information sources
Each resource has its own proprietary way to access it!
7
Need for Common Standards Web Services standards
will allow information from diverse sources to be collected and combined in new ways
Future of the Internet More integrated, useful, smarter,
customizable.
8
Case Study: Google.com Google provides Web Services access
to its search engine (“Google API”). Allows programmers to retrieve
search results using code. “Developer’s Program” encourages
creativity Limits each user to 1000
searches/day
9
GoogleDuel.com An online popularity ranking system. Uses Google’s API to obtain
estimated count of search results for each term.
Example:1. coke (1,010,000)
2. pepsi (633,000)
How about PHP vs ASP?
10
PHP Wins!
GoogleDuel results:1. PHP (86,600,000)2. ASP (78,200,000)
Good news for the PHP community!
11
Uses of GoogleDuel.com Business can analyze their web
presence Compare popularity of company
name, product lines, brands, CEO, slogans with competitors
Use over time can show trends such as growing popularity of a product
12
GoogleDuel for Writers GoogleDuel as a tool for writers
Helps decide what phrase or word to use:
Compare similar words or phrases Use with a thesaurus to check
popularity of a phrase “Writers” version of GoogleDuel
allows comparison of up to 10 phrases at once.
13
GoogleDuel Ultra More sophisticated ranking system. Ranks for a list of adjectives. Examples:
Britney Spears is more popular, but is she more creative or talented?
Which grocery chain has the best service?
Try it at http://www.googleduel.com
14
Other Uses of Google API Gender Guesser
Searches for common patterns involving a first name.
Calculates likelihood person is male or female.
Calculates popularity of name. Works for ethnic names (ex. “Naveen”) Saves data and produces reports, ex:
“Most Popular Names” “Most Feminine Names”
15
Demos (if time) GoogleDuel
http://www.googleduel.com
Gender Guesser http://cgi.sfu.ca/~gpeters/cgi-bin/
pear/gender.php
16
Technical Side Some current Web Services standards: SOAP (Simple Object Access Protocol)
XML based protocol, works over HTTP. Allows variables to be passed to/from a
remote procedure call. Parameter format defined in a WSDL document
Adopted by Microsoft (.NET), Google, Amazon.
17
A competing standard to SOAP
“REST” – “Representational State Transfer”
HTTP based Uses HTTP for security/authentication
Parameters encoded in URL, not in a SOAP envelope.
Returns an XML document. Some advocate it as “second
generation web services” Some sites provide REST interfaces as well as
SOAP.
18
PHP Support for Web Services SOAP package in Pear library
Developed by Shane Caraveo and Arnaud Limbourg
Provides both Client and Server support Makes Web Services easy to write and
access for PHP developers. NuSOAP
An alternate library, quite popular.
19
Example – Accessing Google
include("SOAP/Client.php");
$soapclient = new SOAP_Client('http://api.google.com/search/beta2');$soapoptions = array('namespace' => 'urn:GoogleSearch',
'trace' => 0);
$ret = $soapclient->call('doGoogleSearch', $params = array( 'key' => $key, 'q' => $query, 'start' => 0, 'maxResults' => 1, 'filter' =>
false, 'restrict' => '', 'safeSearch' => false, 'lr' => '', 'ie' => '', 'oe' => '',), $soapoptions);
if (PEAR::isError($ret)) { // error handling goes here
} else // We have proper search results { // Results from the Google search are stored in the object $ret. // in this example, the only thing we need from the search results // is the estimatedTotalResultsCount $num = $ret->estimatedTotalResultsCount; }
20
Growth of Web Services According to IDC Research, "Web
services will become the dominant distributed computing architecture in the next 10 years and will eventually define the fabric of computing."
Reducing integration costs Service-oriented computing as
opposed to presentation-oriented
21
Web Services Business Models Charge small amount per-use of
service Eventually, will Google do this?
Subscription-based services Microsoft’s Mappoint.
Use free Web Services to generate sales and interest Amazon’s storefront approach
22
Other Business Models Better vertical integration
Automated information exchanges between different levels in distribution channels
Business to Business services Mobile Web Services
Web services on wireless devices / cell phones
23
Advantages of Web Services Shorter Development Time
No need to “re-invent the wheel”. Libraries for web services becoming
more stable. Standardized Integration Standardized Access
Use universal HTTP protocol. Can be accessed anywhere on
Internet.
24
Current Challenges Service discovery
How to locate Web Services Create a registry of web services, ex. UDDI
(Universal Description, Discovery, and Integration)
Security and reliability (authentication, encryption) Ex: Use existing protocols such as SSL with
credentials/Token Based authentication Transactions
Multiple transactions – synchronous/asynchronous Performance
25
Comparing Web Services with other Distributed Models Other distributed models:
CORBA, DCOM, Java/RMI For use within a homogeneous system, or
cooperating enterprise systems. Not well suited for use over Internet.
Web Services will not replace these existing standards For use in exchange of information in a
decentralized, distributed environment. i.e. over the Internet.
26
Conclusion Web services are important to the
future of the Internet (service-oriented computing).
PHP libraries make web services easy and accessible for PHP developers.
27
Links Web Services Business Article (USA Today)
http://www.usatoday.com/money/industries/technology/2003-09-30-amazon_x.htm
SOAP http://www.soapware.org REST http://www.xfront.com/REST-Web-Services.html PHP Soap Server Tutorial
http://www.phppatterns.com/index.php/article/articleview/41/1/2/
PHP Soap Client Tutorial http://www.phppatterns.com/index.php/article/articleview/39/1/2/
Web Services Tutorial (By Shane Caraveo) http://talks.php.net/show/soap-phpcon-ny2003/
28
Contacts Geoff Peters (SFU)
www.sfu.ca/~gpeters gpeters at sfu dot ca
Shane Caraveo (ActiveState) shane at caraveo dot com
29
Thank You Questions?