0

I have move my site to another server. After moving I've started to get Soap error as "Could not connect to host". The service I try to connect uses https protocol.

Old server's PHP version : 5.4 New server's PHP version : 5.6.16

There is no error in connection and I successfully connect to server that I wrote codes below :

try {
    $client = new SoapClient('https://www.example.com', [
        'trace' => 1,
        'stream_context'=> stream_context_create(['ssl'=> array('verify_peer'=>false, 'verify_peer_name'=>false)])
    ]); 
} catch (SoapFault $sf) {
    echo $sf->getMessage();
}

But I got error after calling a method :

try {
    $response = $client->method($parameter);
} catch (SoapFault $sf) {
    echo $sf->getMessage();
}

Result of this code : "Could not connect to host".

How can I solve this problem? Many thanks for your interest in advance.

vural
  • 371
  • 2
  • 11

1 Answers1

0

Set this values in your file.

ini_set('soap.wsdl_cache_enabled',0);

ini_set('soap.wsdl_cache_ttl',0);

Try to check your connection by this way also:-

file_get_contents("https://www.example.com");

Try this way also:-

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "https://www.example.com");
$result = curl_exec($ch);
curl_close($ch); 

If all above solutions are not working then write this lines:-

$arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);  

$response = file_get_contents("https://www.example.com", false, stream_context_create($arrContextOptions));

echo $response;

check this link also.

Community
  • 1
  • 1
Ravi
  • 6,311
  • 1
  • 23
  • 41
  • Hello, After file_get_contents, I got these errors. `file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure in ` Another error : `file_get_contents(): Failed to enable crypto in` – vural Jan 08 '16 at 13:07
  • This link will help you. http://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-and-more – Ravi Jan 08 '16 at 13:11
  • Thanks for your interest. I tried but I got the same error. – vural Jan 08 '16 at 13:15
  • You need to install php curl: http://askubuntu.com/questions/9293/how-do-i-install-curl-in-php5 – Ravi Jan 08 '16 at 13:20
  • Curl is already installed to server. Phpinfo() output : cURL support enabled cURL Information 7.38.0 – vural Jan 08 '16 at 13:33
  • Hello, I've already added ssl parameters to my SoapClient connection code. You can see it as stream_context parameters. – vural Jan 08 '16 at 13:57
  • Yeah but my code has file_get_contents. write that params to this function also. do not forget to false as second parameter. – Ravi Jan 08 '16 at 14:00