SOAP
[ class tree: SOAP ] [ index: SOAP ] [ all elements ]

Source for file TCP.php

Documentation is available at TCP.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Shane Caraveo <Shane@Caraveo.com>   Port to PEAR and more   |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: TCP.php,v 1.5 2005/05/03 21:12:46 chagenbu Exp $
  20. //
  21.  
  22. require_once 'SOAP/Server.php';
  23.  
  24. /**
  25.  * SOAP Server Class that implements a TCP SOAP Server.
  26.  * http://www.pocketsoap.com/specs/smtpbinding/
  27.  *
  28.  * This class overrides the default HTTP server, providing the ability to
  29.  * accept socket connections and execute SOAP calls.
  30.  *
  31.  * TODO:
  32.  *   use Net_Socket
  33.  *   implement some security scheme
  34.  *   implement support for attachments
  35.  *
  36.  * @access   public
  37.  * @package  SOAP
  38.  * @author   Shane Caraveo <shane@php.net>
  39.  */
  40. class SOAP_Server_TCP extends SOAP_Server {
  41.  
  42.     var $headers = array();
  43.     var $localaddr;
  44.     var $port;
  45.     var $listen;
  46.     var $reuse;
  47.  
  48.     function SOAP_Server_TCP($localaddr '127.0.0.1'$port = 10000,
  49.                              $listen = 5$reuse = true)
  50.     {
  51.         parent::SOAP_Server();
  52.         $this->localaddr = $localaddr;
  53.         $this->port = $port;
  54.         $this->listen = $listen;
  55.         $this->reuse = $reuse;
  56.     }
  57.  
  58.     function run()
  59.     {
  60.         if (($sock socket_create(AF_INETSOCK_STREAM0)) < 0{
  61.             return $this->_raiseSoapFault('socket_create() failed. Reason: ' socket_strerror($sock));
  62.         }
  63.         if ($this->reuse &&
  64.             !@socket_setopt($sockSOL_SOCKETSO_REUSEADDR1)) {
  65.             return $this->_raiseSoapFault('socket_setopt() failed. Reason: ' socket_strerror(socket_last_error($sock)));
  66.         }
  67.         if (($ret socket_bind($sock$this->localaddr$this->port)) < 0{
  68.             return $this->_raiseSoapFault('socket_bind() failed. Reason: ' socket_strerror($ret));
  69.         }
  70.         if (($ret socket_listen($sock$this->listen)) < 0{
  71.             return $this->_raiseSoapFault('socket_listen() failed. Reason: ' socket_strerror($ret));
  72.         }
  73.  
  74.         while (true{
  75.             $data = null;
  76.             if (($msgsock socket_accept($sock)) < 0{
  77.                 $this->_raiseSoapFault('socket_accept() failed. Reason: ' socket_strerror($msgsock));
  78.                 break;
  79.             }
  80.             while ($buf socket_read($msgsock8192)) {
  81.                 if (!$buf trim($buf)) {
  82.                     continue;
  83.                 }
  84.                 $data .= $buf;
  85.             }
  86.  
  87.             if ($data{
  88.                 $response $this->service($data);
  89.                 /* Write to the socket. */
  90.                 if (!socket_write($msgsock$responsestrlen($response))) {
  91.                     return $this->_raiseSoapFault('Error sending response data reason ' socket_strerror());
  92.                 }
  93.             }
  94.  
  95.             socket_close ($msgsock);
  96.         }
  97.  
  98.         socket_close ($sock);
  99.     }
  100.  
  101.     function service(&$data)
  102.     {
  103.         /* TODO: we need to handle attachments somehow. */
  104.         return $this->parseRequest($data$attachments);
  105.     }
  106. }

Documentation generated on Mon, 11 Mar 2019 14:20:05 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.