[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-db
Subject:    Re: [PHP-DB] Webservices with PHP
From:       Evert Lammerts <evert.lammerts () gmail ! com>
Date:       2008-01-09 20:56:58
Message-ID: 4785351A.3010202 () gmail ! com
[Download RAW message or body]

SOAP stands for Simple Object Access Protocol and is, as its name 
implies, a protocol for accessing objects or in other words, a standard 
that defines how a possibly remote object can be communicated with. 
XML-RPC, with RPC standing for Remote Procedure Call, is a protocol to 
call remote procedures using XML. REST stands for REpresentational State 
Transfer and is an HTTP alternative to Web Service standards, based on 
the idea that the extra layer of these standards is obsolete because the 
HTTP protocol is able to handle similar purposes. Wikipedia.org has 
loads of info.

You say you want to implement a Service Oriented Architecture. The 
reasons you have to do this define what type of standard(s) you should 
use, if any at all. Remember that if you only need to access your 
services through browser based clients (e.g. a website) that there is 
very little use in implementing any of the above mentioned standards and 
protocols. If you need your services to be accessible by a variety of 
clients you do need to explore web service standards (and stop reading on).

A little more specific in the direction of services in PHP accessed by 
browser based clients (assuming you need that), without using web 
service standards. In general most web developers need a lightweight 
protocol to access services, methods and functions through JavaScript. 
For this I use the JavaScript Object Notation (JSON, check json.org).

As a very simple example a service that appends an exclamation mark to 
all parameters you send and alerts them on success. I assume you use 
JavaScript, the json.org JavaScript library and created an 
XmlHttpRequest instance by the name of xhr (check w3schools.com if you 
need help initializing one or use a third party library such as Prototype):

CLIENT SIDE:

//index.html
<script>
function callBack() {
    var response = JSON.parse(xhr.responseText);
    for (x in response)
       alert(x + ' = ' + response[x]);
}

var params = {i: 'need', to: 'use', services:'now'};
var parsed = JSON.stringify(params);
xhr.onreadystatechange = function() {
    if (xhr.readyState == 4)
        callBack();
};
xhr.open ("GET", "service.php?params=" + params, true);
xhr.send (null);
</script>

SERVER SIDE:

//service.php
<?php
    require_once(myservice.php);
    if (!empty($_REQUEST['params']))
       echo 
json_encode(MyService::do_call(json_decode($_REQUEST['params'])));
?>

//myservice.php
<?php
class MyService {
    function doCall($params) {
       foreach ($params as $key => $value)
          $params [$key] .= '!';
       return $params;
    }
}
?>



$P$ $T$ wrote:
> Hi,
> Sorry this may not be related to php-db list. I do not have much
> knowledge about webservices but would like to know, which is better
> way of implementing webservices with PHP-MySQL
>
> XML-RPC, SOAP, or REST
>
> And why? What are the parameters that we should be looking for before
> deciding on mechanism?
>
> Thanks,
> Pravin
>
>   

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic