SoapClient 调用适用于 PHP 5.6 但不适用于 PHP 7

SoapClient call works on PHP 5.6 but not on PHP 7

我有一个可以与 PHP 5.6 (RH6) 一起正常工作的 soapClient 调用。我们正在升级系统到PHP7(RH7,配置与上一个相同)但是同样的调用不起作用。

这是我的代码

$wsdlUrl = "https://THE_URL_I_AM_CALLING/repository/soap/2.1?wsdl";
$sslClientCert =  "../../app/config/ssl/ssl_cert.crt";
$sslClientKey =  "../../app/config/ssl/ssl_cert.key";

$proxy = 'proxy_http';
$port = 8080;

$contextOptions = [
    'ssl' => [
        'local_cert' => $sslClientCert,
        'local_pk' =>  $sslClientKey,
        'SNI_enabled' => true,
        'SNI_server_name' => 'THE_URL_I_AM_CALLING'
    ]
];

$options= [
    "soap_version" => SOAP_1_2,
    "features" => SOAP_SINGLE_ELEMENT_ARRAYS,
    "stream_context" => stream_context_create($contextOptions),
    'proxy_host'     => $proxy,
    'proxy_port'     => $port
];

$client = new SoapClient($wsdlUrl, $options);

try {
        // execute the search
        $searchResults = $client->searchDocuments([
            "text" => "myText",
            "hint" => "document"
        ]);
    }
    catch (Exception $e) {
        echo $e->getMessage();
    }

我在 PHP 7 下得到的错误是

PHP Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host

如果我使用 CURL 进行调用,它就可以工作。

我宁愿使用 clientSoap 让我的生活更轻松。

我找到了解决办法。将它张贴在这里,这样地球上没有其他灵魂需要经历这种考验。

根据文档 http://php.net/manual/en/context.ssl.php#context.ssl.sni-server-name

SNI_server_name (string): If set, then this value will be used as server name for server name indication. If this value is not set, then the server name is guessed based on the hostname used when opening the stream.

Note: This option is deprecated, in favour of peer_name, as of PHP 5.6.0.

更改后:

'SNI_server_name' => 'THE_URL_I_AM_CALLING'

'peer_name' => 'THE_URL_I_AM_CALLING'

有效。