简体   繁体   中英

PHP web page vs Web Service

I have several PHP libraries (scripts and classes and function files) that I want to make available as a service that is web accessible. I am trying to be as deliberate with the wording as possible since it seems that 'Web Service' is rather nuanced. From what I can tell there are 2 main flavors of Web Service, REST and WSDL/SOAP, with the later seeming to be more applicable to what I want to do, but it seems like a lot of overhead and possibly overkill. Could I simply make a PHP page that accepts a parameter of "function" to indicate what action to take, then echo out the response like normal? Requiring the construction of a SOAP message as part of an AJAX call seems horrible.

  • What is the difference between a requesting a PHP page and a Web Service response (aside from the SOAP protocol)?
  • Would you ever return a JSON string in SOAP?
  • Are the implementations separate, exclusive or in parallel?
  • Could you, or even want, to use Apache rewrites to accomplish nearly the same effect as REST or WSDL? Directing the request to a page appending a parameter for the requested action.
  • OR am I over thinking all this and should not worry about SOAP and just got with the standard PHP function parameter and return text or json?

I am also looking ahead a bit, since I work with a lot of legacy code bases, Ruby, Perl, Python, and Java, and would eventually want to make a Service from them as well. Or at least incorporate the libraries somehow.

I am going to recommend this book to you, which is an amazing reference for advanced PHP topics, and is very current. It has a chapter that focuses on networking with PHP, and a specific section on creating your own PHP-based web services. It also contains loads upon loads of other up-to-date kung fu for PHP developers.

http://www.amazon.com/PHP-Advanced-Object-Oriented-Programming-QuickPro/dp/0321832183/

I can tell you what worked for me.

I had to create a small web service in which an outside application needed to get a list of products. I echo'ed a JSON encoded array, while using .htpasswd to protect the data from prying eyes :). The data was accessible very easily with a small CURL script, and it took about 2-3 hours.

If you need the web service users to manage information, if you need an ACL, you will have to look into SOAP and/or REST more. For what I needed - it was more than enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM