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.6 2005/03/14 22:13:16 chagenbu 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.     /**
  49.      * socket
  50.      */
  51.     var $socket = '';
  52.  
  53.     /**
  54.      * SOAP_Transport_TCP Constructor
  55.      *
  56.      * @param string $URL    http url to soap endpoint
  57.      *
  58.      * @access public
  59.      */
  60.     function SOAP_Transport_TCP($URL$encoding = SOAP_DEFAULT_ENCODING)
  61.     {
  62.         parent::SOAP_Base_Object('TCP');
  63.         $this->urlparts = @parse_url($URL);
  64.         $this->url = $URL;
  65.         $this->encoding = $encoding;
  66.     }
  67.  
  68.     function _socket_ping()
  69.     {
  70.         // XXX how do we restart after socket_shutdown?
  71.         //if (!$this->socket) {
  72.             # create socket resource
  73.             $this->socket = @socket_create(AF_INETSOCK_STREAMSOL_TCP);
  74.             if ($this->socket < 0return 0;
  75.  
  76.             # connect
  77.             $result socket_connect($this->socket$this->urlparts['host']$this->urlparts['port']);
  78.             if ($result < 0return 0;
  79.         //}
  80.         return 1;
  81.     }
  82.  
  83.     /**
  84.      * send and receive soap data
  85.      *
  86.      * @param string &$msg       outgoing post data
  87.      * @param string $action      SOAP Action header data
  88.      *
  89.      * @return string|faultresponse
  90.      * @access public
  91.      */
  92.     function &send(&$msg$options = NULL)
  93.     {
  94.         $this->incoming_payload = '';
  95.         $this->outgoing_payload &$msg;
  96.         if (!$this->_validateUrl()) return $this->fault;
  97.  
  98.         // check for TCP scheme
  99.         if (strcasecmp($this->urlparts['scheme']'TCP'== 0{
  100.             // check connection
  101.             if (!$this->_socket_ping())
  102.                 return $this->_raiseSoapFault('error on '.$this->url.' reason '.socket_strerror(socket_last_error($this->socket)));
  103.  
  104.             // write to the socket
  105.             if (!@socket_write($this->socket$this->outgoing_payloadstrlen($this->outgoing_payload))) {
  106.                 return $this->_raiseSoapFault('Error sending data to '.$this->url.' reason '.socket_strerror(socket_last_error($this->socket)));
  107.             }
  108.  
  109.             // shutdown writing
  110.             if(!socket_shutdown($this->socket1))
  111.                 return $this->_raiseSoapFault("can't change socket mode to read.");
  112.  
  113.             // read everything we can.
  114.             while($buf @socket_read($this->socket1024PHP_BINARY_READ)) {
  115.                 $this->incoming_payload .= $buf;
  116.             }
  117.  
  118.             // return payload or die
  119.             if ($this->incoming_payload)
  120.                 return $this->incoming_payload;
  121.  
  122.             return $this->_raiseSoapFault("Error reveiving data from ".$this->url);
  123.         }
  124.  
  125.         return $this->_raiseSoapFault('Invalid url scheme '.$this->url);
  126.     }
  127.  
  128.     /**
  129.      * validate url data passed to constructor
  130.      *
  131.      * @return boolean 
  132.      * @access private
  133.      */
  134.     function _validateUrl()
  135.     {
  136.         if is_array($this->urlparts) ) {
  137.             $this->_raiseSoapFault("Unable to parse URL $url");
  138.             return FALSE;
  139.         }
  140.         if (!isset($this->urlparts['host'])) {
  141.             $this->_raiseSoapFault("No host in URL $url");
  142.             return FALSE;
  143.         }
  144.         if (!isset($this->urlparts['path']|| !$this->urlparts['path'])
  145.             $this->urlparts['path''/';
  146.         return TRUE;
  147.     }
  148.  
  149. }

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