php web service example [closed]

Here are some links to get you started:

http://davidwalsh.name/web-service-php-mysql-xml-json

http://www.ibm.com/developerworks/opensource/tutorials/os-php-webservice/


This is what you need.

Make sure you habe Zend Framework installed - it says how to install it if you don't have it, anyway.

The good thing about it is that it allows Discovery - the rest of the tutorials on the net don't are basic POST/GET - no discovery of services.

<?php
ini_set('include_path', '/usr/share/php/libzend-framework-php/');
require_once 'Zend/Soap/AutoDiscover.php';
require_once "Zend/Soap/Server.php";

class BogdansInjectData {

 private $quotes = array(
    "one" => "answer one");  

  /**
   * @param string $quote
   * @return string
  */

  function PushData($quote) {
    /* just encase the string is in uppercase*/
    $symbol = strtolower($quote);
    /* if there is a quote for the day requested */
    if (isset($this->quotes[$quote])) {
      return $this->quotes[$quote];
    } else {
      /* else error */
      throw new SoapFault("Server","Unknown Symbol '$quote'.");
    }
  }
}

// if(isset($_GET['wsdl'])) {

$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('BogdansInjectData');
$autodiscover->handle();


?>

Thanks, Bogdan

PS: Follow this post as it's the source for the solution and it's constantly updated: http://www.getcomputerservices.co.uk/web-development/php-web-service-with-microsoft-discovery/


Here's a simple example that may help you get started:

https://stackoverflow.com/questions/502547/restful-webservice-to-sum-a-list-of-numbers

And here's a slightly more complicated example:

Php webservice that takes JSON via POST and spits back an image