ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilSoapClient.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
15 {
18 
22  private $log = null;
23 
27  private $client = null;
28 
29  private $uri;
30 
31  private $connect_timeout = 10;
32  private $response_timeout = 10;
33 
34  private $stored_socket_timeout = null;
35 
36 
40  public function __construct($a_uri = '')
41  {
42  global $DIC;
43 
44  $ilSetting = $DIC['ilSetting'];
45 
46  $this->log = ilLoggerFactory::getLogger('wsrv');
47 
48  $this->uri = $a_uri;
49 
50  $this->use_wsdl = true;
51  $timeout = $ilSetting->get('soap_connect_timeout', self::DEFAULT_CONNECT_TIMEOUT);
52  if (!$timeout) {
53  $timeout = self::DEFAULT_CONNECT_TIMEOUT;
54  }
55  $this->connect_timeout = $timeout;
56 
57  $this->response_timeout = self::DEFAULT_RESPONSE_TIMEOUT;
58  }
59 
64  public function getServer()
65  {
66  return $this->uri;
67  }
68 
73  public function setTimeout($a_timeout)
74  {
75  $this->connect_timeout = $a_timeout;
76  }
77 
82  public function getTimeout()
83  {
85  }
86 
90  public function setResponseTimeout($a_timeout)
91  {
92  $this->response_timeout = (int) $a_timeout;
93  }
94 
98  public function getResponseTimeout()
99  {
101  }
102 
107  public function enableWSDL($a_stat)
108  {
109  $this->use_wsdl = $a_stat;
110  }
111 
116  public function enabledWSDL()
117  {
118  return $this->use_wsdl;
119  }
120 
121 
125  public function init()
126  {
127  global $DIC;
128 
129  $ilSetting = $DIC['ilSetting'];
130 
131  if (!strlen(trim($this->getServer()))) {
132  if (strlen(trim($ilSetting->get('soap_wsdl_path', '')))) {
133  $this->uri = $ilSetting->get('soap_wsdl_path', '');
134  } else {
135  $this->uri = ilUtil::_getHttpPath() . '/webservice/soap/server.php?wsdl';
136  }
137  }
138  try {
139  $this->log->debug('Using wsdl: ' . $this->getServer());
140  $this->log->debug('Using connection timeout: ' . $this->getTimeout());
141  $this->log->debug('Using response timeout: ' . $this->getResponseTimeout());
142 
143  $this->setSocketTimeout(true);
144  $this->client = new SoapClient(
145  $this->uri,
146  array(
147  'exceptions' => true,
148  'trace' => 1,
149  'connection_timeout' => (int) $this->getTimeout()
150  )
151  );
152  return true;
153  } catch (SoapFault $ex) {
154  $this->log->warning('Soap init failed with message: ' . $ex->getMessage());
155  $this->resetSocketTimeout();
156  return false;
157  } finally {
158  $this->resetSocketTimeout();
159  }
160  }
161 
166  protected function setSocketTimeout($a_wsdl_mode)
167  {
168  $this->stored_socket_timeout = ini_get('default_socket_timeout');
169  $this->log->debug('Default socket timeout is: ' . $this->stored_socket_timeout);
170 
171  if ($a_wsdl_mode) {
172  $this->log->debug('WSDL mode, using socket timeout: ' . $this->getTimeout());
173  ini_set('default_socket_timeout', $this->getTimeout());
174  } else {
175  $this->log->debug('Non WSDL mode, using socket timeout: ' . $this->getResponseTimeout());
176  ini_set('default_socket_timeout', $this->getResponseTimeout());
177  }
178  return true;
179  }
180 
185  protected function resetSocketTimeout()
186  {
187  ini_set('default_socket_timeout', $this->stored_socket_timeout);
188  $this->log->debug('Restoring default socket timeout to: ' . $this->stored_socket_timeout);
189  return true;
190  }
191 
197  public function call($a_operation, $a_params)
198  {
199  $this->log->debug('Calling webservice: ' . $a_operation);
200 
201  $this->setSocketTimeout(false);
202  try {
203  return $this->client->__call($a_operation, $a_params);
204  } catch (SoapFault $exception) {
205  $this->log->error('Calling webservice failed with message: ' . $exception->getMessage());
206  $this->log->debug($this->client->__getLastResponseHeaders());
207  $this->log->debug($this->client->__getLastResponse());
208  return false;
209  } catch (Exception $exception) {
210  $this->log->error('Caught unknown exception with message: ' . $exception->getMessage());
211  $this->log->debug($this->client->__getLastResponseHeaders());
212  $this->log->debug($this->client->__getLastResponse());
213  } finally {
214  $this->resetSocketTimeout();
215  }
216  }
217 }
call($a_operation, $a_params)
Call webservice method.
enableWSDL($a_stat)
enable wsdl mode
resetSocketTimeout()
Reset socket default timeout to defaults.
const DEFAULT_RESPONSE_TIMEOUT
global $DIC
Definition: saml.php:7
setSocketTimeout($a_wsdl_mode)
Set socket timeout.
const DEFAULT_CONNECT_TIMEOUT
enabledWSDL()
Check if wsdl is enabled.
init()
Init soap client.
setTimeout($a_timeout)
Set connect timeout.
setResponseTimeout($a_timeout)
static _getHttpPath()
global $ilSetting
Definition: privfeed.php:17
static getLogger($a_component_id)
Get component logger.
getServer()
Get server uri.
getTimeout()
Get connect timeout.
__construct($a_uri='')