PHP判断网络连通
2023-02-18 16:43:42 时间
PHP代理其实挺麻烦的。。。
仅测试连通性
$connected = @fsockopen("blog.phpgao.com", 80);
if ($connected){
$is_conn = true;
@fclose($connected);
}else{
$is_conn = false;
}
return $is_conn;
并测试可用性
//默认三秒超时
@ini_set('default_socket_timeout', 3);
$fp = @fsockopen($proxy_server, $proxy_port, $errno, $errstr, 30);
if (!$fp) {
BizResult::ensureNotFalse(false, Constants::WEB_ERROR_SRV_UPDATE_PROXY);
} else {
//$result['reason'] = '已通过测试,代理工作正常。';
fclose($fp);
}
$url = 'http://blog.phpgao.com/';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY, $proxy_server);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_user . ':' . $proxy_password);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$rtn = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// if(curl_errno($ch)){
// echo curl_error($ch);exit();
// }
if (200 !== $httpCode) {
BizResult::ensureNotFalse(false, Constants::WEB_ERROR_SRV_UPDATE_PROXY);
}
curl_close($ch);
相关文章
- C++基础篇之什么是 数据结构
- Hello DPU,Goodbye CPU!
- C++基础篇之什么是数据类型
- Golang ast 的使用
- c++中的std::stod, stCPP程序说明std::stod():stof, std::stold
- php解压文件
- 堪称一站式管理平台,同时支持Linux、MySQL、Redis、MongoDB可视化管理!
- Golang语言情怀--第94期 区块链技术-centos安装部署IPFS
- Golang语言情怀--第96期 区块链技术-以太坊公链合约部署-第2节:本地合约部署
- Golang语言情怀--第97期 区块链技术-以太坊公链合约部署-第3节:合约转Go语言代码
- Golang语言情怀--第98期 区块链技术-以太坊公链合约部署-第4节:MetaMask钱包连接到本地环境
- Golang语言情怀--第99期 区块链技术-以太坊公链合约部署-第5节:部署合约到以太坊公链
- Golang语言情怀--第100期 区块链技术-以太坊公链NFT图片去中心化存储-第1节:IPFS存储方案
- Golang语言情怀--第101期 区块链技术-以太坊公链NFT图片去中心化存储-第2节:go语言实现IPFS存储demo
- Golang语言情怀--第102期 区块链技术-通过区块链技术告诉你是“斯人”还是“是人”
- Golang语言情怀--第103期 区块链技术-关于区块链中的智能合约:您想知道的一切
- Power BI模拟谷歌2022搜索排行榜
- gTasks Pro for Mac(Google任务管理器) 中文
- mongodb的安装
- 关于GO语言,这篇文章讲的很明白