SOAP--Transport--TCP
[ class tree: SOAP--Transport--TCP ] [ index: SOAP--Transport--TCP ] [ 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 Hanna <iordy_at_iordy_dot_com>                        |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: TCP.php,v 1.3 2003/04/13 21:38:58 shane Exp $
  20. //
  21.  
  22. require_once 'SOAP/Base.php';
  23.  
  24. /**
  25. *  TCP Transport for SOAP
  26. *
  27. * TODO:
  28. *   use Net_Socket
  29. *   implement some security scheme
  30. *   implement support for attachments
  31. *
  32. *
  33. @access public
  34. @package SOAP::Transport::TCP
  35. @author Shane Hanna <iordy_at_iordy_dot_com>
  36. */
  37. {
  38.  
  39.     var $headers = array();
  40.     var $urlparts = NULL;
  41.     var $url = '';
  42.     var $incoming_payload = '';
  43.     var $_userAgent = SOAP_LIBRARY_NAME;
  44.     var $encoding = SOAP_DEFAULT_ENCODING;
  45.     var $result_encoding = 'UTF-8';
  46.     var $result_content_type;
  47.  
  48.     # socket
  49.     var $socket = '';
  50.  
  51.     /**
  52.     * SOAP_Transport_TCP Constructor
  53.     *
  54.     * @param string $URL    http url to soap endpoint
  55.     *
  56.     * @access public
  57.     */
  58.     function SOAP_Transport_TCP($URL$encoding = SOAP_DEFAULT_ENCODING)
  59.     {
  60.         parent::SOAP_Base_Object('TCP');
  61.         $this->urlparts = @parse_url($URL);
  62.         $this->url = $URL;
  63.         $this->encoding = $encoding;
  64.     }
  65.  
  66.     function _socket_ping ({
  67.         // XXX how do we restart after socket_shutdown?
  68.         //if (!$this->socket) {
  69.             # create socket resource
  70.             $this->socket = @socket_create(AF_INETSOCK_STREAMSOL_TCP);
  71.             if ($this->socket < 0return 0;
  72.  
  73.             # connect
  74.             $result socket_connect($this->socket$this->urlparts['host']$this->urlparts['port']);
  75.             if ($result < 0return 0;
  76.         //}
  77.         return 1;
  78.     }
  79.  
  80.     /**
  81.     * send and receive soap data
  82.     *
  83.     * @param string &$msg       outgoing post data
  84.     * @param string $action      SOAP Action header data
  85.     *
  86.     * @return string|faultresponse
  87.     * @access public
  88.     */
  89.     function &send(&$msg$options = NULL)
  90.     {
  91.         $this->incoming_payload = '';
  92.         $this->outgoing_payload &$msg;
  93.         if (!$this->_validateUrl()) return $this->fault;
  94.  
  95.         # check for TCP scheme
  96.         if (strcasecmp($this->urlparts['scheme']'TCP'== 0{
  97.             # check connection
  98.             if (!$this->_socket_ping())
  99.                 return $this->_raiseSoapFault('error on '.$this->url.' reason '.socket_strerror(socket_last_error($this->socket)));
  100.  
  101.             # write to the socket
  102.             if (!@socket_write($this->socket$this->outgoing_payloadstrlen($this->outgoing_payload))) {
  103.                 return $this->_raiseSoapFault('Error sending data to '.$this->url.' reason '.socket_strerror(socket_last_error($this->socket)));
  104.             }
  105.  
  106.             # shutdown writing
  107.             if(!socket_shutdown($this->socket1))
  108.                 return $this->_raiseSoapFault("can't change socket mode to read.");
  109.  
  110.             # read everything we can.
  111.             while($buf @socket_read($this->socket1024PHP_BINARY_READ)) {
  112.                 $this->incoming_payload .= $buf;
  113.             }
  114.  
  115.             # return payload or die
  116.             if ($this->incoming_payload)
  117.                 return $this->incoming_payload;
  118.             
  119.             return $this->_raiseSoapFault("Error reveiving data from ".$this->url);
  120.         }
  121.         return $this->_raiseSoapFault('Invalid url scheme '.$this->url);
  122.     }
  123.  
  124.     // private members
  125.  
  126.     /**
  127.     * validate url data passed to constructor
  128.     *
  129.     * @return boolean 
  130.     * @access private
  131.     */
  132.     function _validateUrl()
  133.     {
  134.         if is_array($this->urlparts) ) {
  135.             $this->_raiseSoapFault("Unable to parse URL $url");
  136.             return FALSE;
  137.         }
  138.         if (!isset($this->urlparts['host'])) {
  139.             $this->_raiseSoapFault("No host in URL $url");
  140.             return FALSE;
  141.         }
  142.         if (!isset($this->urlparts['path']|| !$this->urlparts['path'])
  143.             $this->urlparts['path''/';
  144.         return TRUE;
  145.     }
  146.  
  147. }
  148. ?>

Documentation generated on Mon, 11 Mar 2019 13:59:47 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.