PHP WDSL Error on new server

kevbob650
kevbob650 used Ask the Experts™
on
I'm loading existing PHP code onto a new server and getting a fatal error with a soap wsdl:  

$this->client = new SoapClient(
      "https://servername.jws?WSDL",
      array("classmap" => $this->classmap,
      "location" => "https://servername.jws",
      "trace" => true,
      "exceptions" => true
      )
);

PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://servername.jws?WSDL' failed to load external entity 'https://servername.jws?WSDL'

If I test the wsdl in a test page:
$wsdl = "https://servername.jws?WSDL";
echo file_get_contents($wsdl);

I get an ssl error:
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

A co-worker suggested this:
$arrContextOptions=array
(
    "ssl"=>array
                (
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);

This works for the test scenario, but I have no idea how to incorporate it into the soap client???
Or is there another avenue to resolve the issue???
Any help would be appreciated!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
You can pass a stream_context to the SoapClient Constructor like this
// Create the context as you did in your test
$context = stream_context_create(
  array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
));
// PASS IT TO THE SoapClient CONSTRUCTOR LIKE THIS
$this->client = new SoapClient(
      "https://servername.jws?WSDL",
      array("classmap" => $this->classmap,
      "location" => "https://servername.jws",
      "trace" => true,
      "exceptions" => true,
      "stream_context" => $context
      )
);

Open in new window

Author

Commented:
Thanks so much!  That was it, and I learned something new!
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are most welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial