我目前正在与SOAP服务集成,该服务定义了两个不同的服务。
WSDL的相关部分是:
<wsdl:service name="Config"> <wsdl:port name="BasicHttpBinding_IConfiguration" binding="tns:BasicHttpBinding_IConfiguration"> <soap:address location="http://nonsecure.example.com/Configuration.svc"/> </wsdl:port> <wsdl:port name="BasicHttpsBinding_IConfiguration" binding="tns:BasicHttpsBinding_IConfiguration"> <soap:address location="https://secure.example.com/Configuration.svc"/> </wsdl:port> </wsdl:service>
通过研究,我发现可以使用__setLocation()方法来控制
$client->__setLocation('https://secure.example.com/Configuration.svc');但是,我不应该直接写死它,应该根据端口优先选择https。
于是封装一个方法来优先获取https端口
function getLocationForPort($wsdl, $portName)
{
$file = file_get_contents($wsdl);
$xml = new SimpleXmlElement($file);
$query = "wsdl:service/wsdl:port[@name='$portName']/soap:address";
$address = $xml->xpath($query);
if (!empty($address))
{
$location = (string)$address[0]['location'];
return $location;
}
return false;
}用法很简单:
$client = new SoapClient($wsdl);
$sslLocation = getLocationForPort($wsdl, 'BasicHttpsBinding_IConfiguration');
if ($sslLocation)
{
$client->__setLocation($location);
}
(1).在PHP中可以查看的环境变量包括: (1.1).电脑环境变量 (2.1).服务器环境变量(2).getenv()函数获取一个环境变量的值.参数1是环境变量的key,参数2值为true的时候仅从你的电脑环境变量中查找,参数2值为false会从两种变量中全部查询//获取我电脑登录的用户名,输出A...
概念请参考w3school文章: redis watch ,redis exec (看完基本秒懂)(1)基本事务://连接本地的 Redis 服务 $redis = new Redis(); $redis->con...
为什么使用队列?因为pop取队列具有原子性。假如我们需要秒杀一个商品id,我们先将商品的库存保存到一个队列。例如:<?php $redis = new Redis(); $redis->connect('127.0.0.1', 6...
文章篇幅较长,如果不喜欢看文章的,此处抛出韩顺丰老师的位运算视频,韩老师应该是全网讲php位运算符最详细的一个老师了。链接:https://pan.baidu.com/s/14xj7er8eVSUcJ-jYXyA0GA 提取码:731m 链接:https://pan.baidu.com...
在正式介绍前先抛出一段代码:<?php //输入的密码 $password = empty($_POST['password']) ? 0 : $_POST['password']; //设置的密码...
(1).今天遇到一件奇怪的事情,在event事件中是无法自定义异常处理,例如我们使用set_exception_handler来统一处理异常。例如下面的代码:<?php error_reporting(E_ALL); set_error_handler(function ($errn...