php and-web-services-24402
DESCRIPTION
TRANSCRIPT
![Page 2: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/2.jpg)
PHP and Web Services
Summary
• What is PHP?
• Web Services
• SOAP
• REST
• JSON
• Conclusions
2
![Page 3: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/3.jpg)
PHP and Web Services
What is PHP?
• PHP: Hypertext Preprocessor
• Open Source Web scripting language
• Created in 1994
• Syntax inherited from C, Java and Perl
• Powerful, yet easy to learn
3
![Page 4: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/4.jpg)
PHP and Web Services
How is PHP used?
• Content Management
• Forums
• Blogging
• Wiki
• CRM
4
![Page 5: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/5.jpg)
PHP and Web Services
Who uses PHP?
Source: Zend
5
![Page 6: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/6.jpg)
PHP and Web Services
Why use PHP?
• Used by 20M+ Web Sites around the globe
• Community-maintained documentation
• Code runs on UNIX, OSX and Windows
• Backed commercially by Zend
• Easy syntax
6
![Page 7: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/7.jpg)
PHP and Web Services
The PHP language
7
Easy syntax!
![Page 8: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/8.jpg)
PHP and Web Services
Creating a function
8
function declaration
return value
function call
![Page 9: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/9.jpg)
PHP and Web Services
Creating a class
9
class declaration
public method
method call
![Page 10: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/10.jpg)
PHP and Web Services
Web Services
10
Source: The Server Side(http://tinyurl.com/38umxt)
![Page 11: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/11.jpg)
PHP and Web Services
What are Web Services?
• Interoperable interactions
• Calls are made over a network
• Lots of different standards
• Popular Web sites use them
11
![Page 12: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/12.jpg)
PHP and Web Services
Requirements
• PHP 5.2.2
• SOAP
• simplexml
• DOM
• JSON
12
![Page 13: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/13.jpg)
PHP and Web Services
SOAP
Source: Prentice Hall(http://tinyurl.com/33dcch)
13
![Page 14: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/14.jpg)
PHP and Web Services
SOAP
• Simple Object Access Protocol
• Usually an HTTP POST request
• Call is encapsulated in XML
• Response is an XML document
• PHP handles everything
14
![Page 15: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/15.jpg)
PHP and Web Services
Server implementation
15
namespace
start a server
assign a class
handle incoming calls
![Page 16: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/16.jpg)
PHP and Web Services
Client implementation
16
namespace
endpoint
display result
![Page 17: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/17.jpg)
PHP and Web Services
Output
17
namespace
result
![Page 18: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/18.jpg)
PHP and Web Services
SOAP
18
• Support for SOAP 1.1, 1.2 and WSDL 1.1
• Handles simple and complex types
• Very easy implementation
• Output is quite bulky
![Page 19: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/19.jpg)
PHP and Web Services
REST
http://example.com/calculator/sum/?x=121&y=233
GETPUTPOSTDELETE
«interface»
ResourceGET - perform a calculationPUT - not usedPOST - not usedDELETE - not used
/calculator/sum/
19
![Page 20: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/20.jpg)
PHP and Web Services
REST
• Representational State Transfer
• Usually an HTTP GET request
• Call is made through GET parameters
• Response is an XML document
• Create response with DOM
• Interpret response with simplexml
20
![Page 21: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/21.jpg)
PHP and Web Services
Server implementation
21
handle incoming call
create anXML document
add elements
output result
![Page 22: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/22.jpg)
PHP and Web Services
Client implementation
22
endpoint
arguments
load XML document
output result
![Page 23: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/23.jpg)
PHP and Web Services
Output
23
result
![Page 24: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/24.jpg)
PHP and Web Services
REST
24
• Interaction needs to be implemented
• XML schema must be know beforehand
• Complex types not handled natively
• Output is usually RSS
![Page 25: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/25.jpg)
PHP and Web Services
JSON
25
JSON LogoSource: json.org
![Page 26: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/26.jpg)
PHP and Web Services
JSON
• JavaScript Object Notation
• REST approach
• Except response is not XML
• Used on the client side
• Create response with json_encode()
• Interpret response in JavaScript
26
![Page 27: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/27.jpg)
PHP and Web Services
Server implementation
27
handle incoming call
generate result
outputJSON string
![Page 28: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/28.jpg)
PHP and Web Services
Client implementation
28
endpoint
arguments
output result
![Page 29: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/29.jpg)
PHP and Web Services
Output
29
result
![Page 30: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/30.jpg)
PHP and Web Services
JSON
30
• REST approach
• Handles simple and complex types
• Calls can be made with AJAX
• Can also be used on the server side
![Page 31: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/31.jpg)
PHP and Web Services
Conclusions
• PHP is a powerful web scripting language
• Too many Web Services standards
• PHP handles all the internals
• REST requires more coding than SOAP
• Use JSON for client side applications
• XML-RPC support is still experimental
31
![Page 32: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/32.jpg)
PHP and Web Services
Questions?
32
![Page 33: Php and-web-services-24402](https://reader033.vdocuments.net/reader033/viewer/2022042813/5492860dac795959288b480f/html5/thumbnails/33.jpg)
PHP and Web Services
Resources
33
• My blog: http://unfoldingtheweb.com/
• PHP Manual: http://www.php.net/
• SOAP: http://www.w3.org/TR/soap/
• REST: http://tinyurl.com/akhc7
• JSON: http://www.json.org/