function soap_transport_http::connect in Salesforce Suite 5
Same name in this branch
- 5 includes/nusoap.php \soap_transport_http::connect()
- 5 includes/nusoap.orig.php \soap_transport_http::connect()
Same name and namespace in other branches
- 5.2 includes/nusoap.php \soap_transport_http::connect()
- 5.2 includes/nusoap.orig.php \soap_transport_http::connect()
2 calls to soap_transport_http::connect()
- soap_transport_http::send in includes/
nusoap.php - * send the SOAP message via HTTP * *
- soap_transport_http::send in includes/
nusoap.orig.php - * send the SOAP message via HTTP * *
File
- includes/
nusoap.php, line 2087
Class
- soap_transport_http
- transport class for sending/receiving data via HTTP and HTTPS NOTE: PHP must be compiled with the CURL extension for HTTPS support
Code
function connect($connection_timeout = 0, $response_timeout = 30) {
// For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like
// "regular" socket.
// TODO: disabled for now because OpenSSL must be *compiled* in (not just
// loaded), and until PHP5 stream_get_wrappers is not available.
// if ($this->scheme == 'https') {
// if (version_compare(phpversion(), '4.3.0') >= 0) {
// if (extension_loaded('openssl')) {
// $this->scheme = 'ssl';
// $this->debug('Using SSL over OpenSSL');
// }
// }
// }
$this
->debug("connect connection_timeout {$connection_timeout}, response_timeout {$response_timeout}, scheme {$this->scheme}, host {$this->host}, port {$this->port}");
if ($this->scheme == 'http' || $this->scheme == 'ssl') {
// use persistent connection
if ($this->persistentConnection && isset($this->fp) && is_resource($this->fp)) {
if (!feof($this->fp)) {
$this
->debug('Re-use persistent connection');
return true;
}
fclose($this->fp);
$this
->debug('Closed persistent connection at EOF');
}
// munge host if using OpenSSL
if ($this->scheme == 'ssl') {
$host = 'ssl://' . $this->host;
}
else {
$host = $this->host;
}
$this
->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout);
// open socket
if ($connection_timeout > 0) {
$this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str, $connection_timeout);
}
else {
$this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str);
}
// test pointer
if (!$this->fp) {
$msg = 'Couldn\'t open socket connection to server ' . $this->url;
if ($this->errno) {
$msg .= ', Error (' . $this->errno . '): ' . $this->error_str;
}
else {
$msg .= ' prior to connect(). This is often a problem looking up the host name.';
}
$this
->debug($msg);
$this
->setError($msg);
return false;
}
// set response timeout
$this
->debug('set response timeout to ' . $response_timeout);
socket_set_timeout($this->fp, $response_timeout);
$this
->debug('socket connected');
return true;
}
else {
if ($this->scheme == 'https') {
if (!extension_loaded('curl')) {
$this
->setError('CURL Extension, or OpenSSL extension w/ PHP version >= 4.3 is required for HTTPS');
return false;
}
$this
->debug('connect using https');
// init CURL
$this->ch = curl_init();
// set url
$hostURL = $this->port != '' ? "https://{$this->host}:{$this->port}" : "https://{$this->host}";
// add path
$hostURL .= $this->path;
curl_setopt($this->ch, CURLOPT_URL, $hostURL);
// follow location headers (re-directs)
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
// ask for headers in the response output
curl_setopt($this->ch, CURLOPT_HEADER, 1);
// ask for the response output as the return value
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
// encode
// We manage this ourselves through headers and encoding
// if(function_exists('gzuncompress')){
// curl_setopt($this->ch, CURLOPT_ENCODING, 'deflate');
// }
// persistent connection
if ($this->persistentConnection) {
// The way we send data, we cannot use persistent connections, since
// there will be some "junk" at the end of our request.
//curl_setopt($this->ch, CURL_HTTP_VERSION_1_1, true);
$this->persistentConnection = false;
$this->outgoing_headers['Connection'] = 'close';
$this
->debug('set Connection: ' . $this->outgoing_headers['Connection']);
}
// set timeout
if ($connection_timeout != 0) {
curl_setopt($this->ch, CURLOPT_TIMEOUT, $connection_timeout);
}
// TODO: cURL has added a connection timeout separate from the response timeout
//if ($connection_timeout != 0) {
// curl_setopt($this->ch, CURLOPT_CONNECTIONTIMEOUT, $connection_timeout);
//}
//if ($response_timeout != 0) {
// curl_setopt($this->ch, CURLOPT_TIMEOUT, $response_timeout);
//}
// recent versions of cURL turn on peer/host checking by default,
// while PHP binaries are not compiled with a default location for the
// CA cert bundle, so disable peer/host checking.
//curl_setopt($this->ch, CURLOPT_CAINFO, 'f:\php-4.3.2-win32\extensions\curl-ca-bundle.crt');
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 0);
// support client certificates (thanks Tobias Boes, Doug Anarino, Eryan Ariobowo)
if ($this->authtype == 'certificate') {
if (isset($this->certRequest['cainfofile'])) {
curl_setopt($this->ch, CURLOPT_CAINFO, $this->certRequest['cainfofile']);
}
if (isset($this->certRequest['verifypeer'])) {
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, $this->certRequest['verifypeer']);
}
else {
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, 1);
}
if (isset($this->certRequest['verifyhost'])) {
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, $this->certRequest['verifyhost']);
}
else {
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 1);
}
if (isset($this->certRequest['sslcertfile'])) {
curl_setopt($this->ch, CURLOPT_SSLCERT, $this->certRequest['sslcertfile']);
}
if (isset($this->certRequest['sslkeyfile'])) {
curl_setopt($this->ch, CURLOPT_SSLKEY, $this->certRequest['sslkeyfile']);
}
if (isset($this->certRequest['passphrase'])) {
curl_setopt($this->ch, CURLOPT_SSLKEYPASSWD, $this->certRequest['passphrase']);
}
}
$this
->debug('cURL connection set up');
return true;
}
else {
$this
->setError('Unknown scheme ' . $this->scheme);
$this
->debug('Unknown scheme ' . $this->scheme);
return false;
}
}
}