0
PHP and Web Services
      CITOT - May    20th   2007
   Bruno Pedro <bpedro@computer.org>
Summary
 • What is PHP?
 • Web Services
  • SOAP
  • REST
  • JSON
 • Conclusions
PHP and Web Services      2
What is PHP?

  • PHP: Hypertext Preprocessor
  • Open Source Web scripting language
  • Created in 1994
  • Syntax inheri...
How is PHP used?

  • Content Management
  • Forums
  • Blogging
  • Wiki
  • CRM
PHP and Web Services   4
Who uses PHP?




                              Source: Zend



PHP and Web Services   5
Why use PHP?

  • Used by 20M+ Web Sites around the globe
  • Community-maintained documentation
  • Code runs on UNIX, OS...
The PHP language


                           Easy syntax!




PHP and Web Services   7
Creating a function
                           function declaration


                            return value


         ...
Creating a class
                           class declaration


                           public method




             ...
Web Services




                                  Source:The Server Side
                              (http://tinyurl.co...
What are Web Services?

  • Interoperable interactions
  • Calls are made over a network
  • Lots of different standards
 ...
Requirements

  • PHP 5.2.2
  • SOAP
  • simplexml
  • DOM
  • JSON
PHP and Web Services   12
SOAP




                                     Source: Prentice Hall
                              (http://tinyurl.com/33dc...
SOAP

  • Simple Object Access Protocol
  • Usually an HTTP POST request
  • Call is encapsulated in XML
  • Response is a...
Server implementation

                                               namespace




                                      ...
Client implementation
                                namespace




                                   endpoint



       ...
Output
                                   namespace




                          result

PHP and Web Services     17
SOAP

  • Support for SOAP 1.1, 1.2 and WSDL 1.1
  • Handles simple and complex types
  • Very easy implementation
  • Out...
REST
      «interface»
                                    /calculator/sum/
       Resource
                              ...
REST
  • Representational State Transfer
  • Usually an HTTP GET request
  • Call is made through GET parameters
  • Respo...
Server implementation
                                handle incoming call



                                      create...
Client implementation

                                        endpoint

                                     arguments


...
Output



                              result




PHP and Web Services     23
REST

  • Interaction needs to be implemented
  • XML schema must be know beforehand
  • Complex types not handled nativel...
JSON




                                 JSON Logo
                             Source: json.org




PHP and Web Services...
JSON
  • JavaScript Object Notation
  • REST approach
  • Except response is not XML
  • Used on the client side
  • Creat...
Server implementation

                            handle incoming call



                                         genera...
Client implementation
                                            endpoint



                                            ...
Output



                              result




PHP and Web Services     29
JSON

  • REST approach
  • Handles simple and complex types
  • Calls can be made with AJAX
  • Can also be used on the s...
Conclusions
  • PHP is a powerful web scripting language
  • Too many Web Services standards
  • PHP handles all the inter...
Questions?




PHP and Web Services       32
Resources
  • My blog: http://unfoldingtheweb.com/

  • PHP Manual: http://www.php.net/
  • SOAP: http://www.w3.org/TR/soa...
Upcoming SlideShare
Loading in...5
×

PHP and Web Services

41,511

Published on

A walk through PHP and the implementation of SOAP, REST and JSON servers and clients using only native functions.

Published in: Technology
3 Comments
41 Likes
Statistics
Notes
No Downloads
Views
Total Views
41,511
On Slideshare
0
From Embeds
0
Number of Embeds
21
Actions
Shares
0
Downloads
2,166
Comments
3
Likes
41
Embeds 0
No embeds

No notes for slide

Transcript of "PHP and Web Services"

  1. 1. PHP and Web Services CITOT - May 20th 2007 Bruno Pedro <bpedro@computer.org>
  2. 2. Summary • What is PHP? • Web Services • SOAP • REST • JSON • Conclusions PHP and Web Services 2
  3. 3. 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 PHP and Web Services 3
  4. 4. How is PHP used? • Content Management • Forums • Blogging • Wiki • CRM PHP and Web Services 4
  5. 5. Who uses PHP? Source: Zend PHP and Web Services 5
  6. 6. 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 PHP and Web Services 6
  7. 7. The PHP language Easy syntax! PHP and Web Services 7
  8. 8. Creating a function function declaration return value function call PHP and Web Services 8
  9. 9. Creating a class class declaration public method method call PHP and Web Services 9
  10. 10. Web Services Source:The Server Side (http://tinyurl.com/38umxt) PHP and Web Services 10
  11. 11. What are Web Services? • Interoperable interactions • Calls are made over a network • Lots of different standards • Popular Web sites use them PHP and Web Services 11
  12. 12. Requirements • PHP 5.2.2 • SOAP • simplexml • DOM • JSON PHP and Web Services 12
  13. 13. SOAP Source: Prentice Hall (http://tinyurl.com/33dcch) PHP and Web Services 13
  14. 14. SOAP • Simple Object Access Protocol • Usually an HTTP POST request • Call is encapsulated in XML • Response is an XML document • PHP handles everything PHP and Web Services 14
  15. 15. Server implementation namespace start a server assign a class handle incoming calls PHP and Web Services 15
  16. 16. Client implementation namespace endpoint display result PHP and Web Services 16
  17. 17. Output namespace result PHP and Web Services 17
  18. 18. SOAP • Support for SOAP 1.1, 1.2 and WSDL 1.1 • Handles simple and complex types • Very easy implementation • Output is quite bulky PHP and Web Services 18
  19. 19. REST «interface» /calculator/sum/ Resource GET - perform a calculation GET PUT - not used PUT POST - not used POST DELETE - not used DELETE http://example.com/calculator/sum/?x=121&y=233 PHP and Web Services 19
  20. 20. 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 PHP and Web Services 20
  21. 21. Server implementation handle incoming call create an XML document add elements output result PHP and Web Services 21
  22. 22. Client implementation endpoint arguments load XML document output result PHP and Web Services 22
  23. 23. Output result PHP and Web Services 23
  24. 24. REST • Interaction needs to be implemented • XML schema must be know beforehand • Complex types not handled natively • Output is usually RSS PHP and Web Services 24
  25. 25. JSON JSON Logo Source: json.org PHP and Web Services 25
  26. 26. 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 PHP and Web Services 26
  27. 27. Server implementation handle incoming call generate result output JSON string PHP and Web Services 27
  28. 28. Client implementation endpoint arguments output result PHP and Web Services 28
  29. 29. Output result PHP and Web Services 29
  30. 30. JSON • REST approach • Handles simple and complex types • Calls can be made with AJAX • Can also be used on the server side PHP and Web Services 30
  31. 31. 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 PHP and Web Services 31
  32. 32. Questions? PHP and Web Services 32
  33. 33. Resources • 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/ PHP and Web Services 33
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×