php soap 如何设置超时?

php soap 如何设置超时?,第1张

在使用soap前,先检查soap的url是否可访问。如为true则继续执行Soap,否则给出超时提醒。

下面是我经常使用的判断网站链接是否可用的函数,希望对你有用。

//判断URL在指定时间内是否有相应

function checkUrl($url, $timeout = 3){

$ret = false

$handle = curl_init()

curl_setopt($handle, CURLOPT_URL,$url)

curl_setopt($handle, CURLOPT_NOBODY, true)

curl_setopt($handle, CURLOPT_TIMEOUT,$timeout)//设置默认超时时间为3秒

$result = curl_exec($handle)

$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE)

curl_close($handle)

if(strpos($httpCode,'2') == 0){

$ret = true

}

return $ret

}

呵呵 ,我看你好像前面问过一个问题 是说怎么判断程序走了5秒是吧.你可能理解错了 你在new soapclent之前 只要 设置超时时间就可以了.ini_set('default_socket_timeout', 5)//设置超时时间


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11154349.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存