当前位置:网站首页>PHP detects whether the URL URL link is normally accessible
PHP detects whether the URL URL link is normally accessible
2022-07-28 11:27:00 【Curtain dust maple】
Reading guide :
In some scenarios , Need to access URL URL link implementation http request , If the URL link is blocked ( For example, the server is shut down ), that http The request will be blocked ,PHP It's single threaded , Once there is no response for a long time , It will give users a very bad experience . therefore , A good solution is to check whether the website can be connected normally .
Method 1 :
/**
* Check whether the URL connection is available
**/
function check_url($url){
if (@fopen($url, 'r')==false) {
return false;
}
return true;
}Method 2 :
/**
* Check whether the URL connection is available
**/
function check_url($url){
$httpcode = 0;
$ch = curl_init();
$timeout = 1; // Set the timeout time [ Company : second ]
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch,CURLOPT_URL,$url);
curl_exec($ch);
# Get status code assignment
$httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode == 200){
return true;
}else{
return false;
}
}边栏推荐
- 【MySQL从入门到精通】【高级篇】(十)MyISAM的索引方案&&索引的优缺点
- A solution to the problem that ThinkPad fingerprint verification cannot be used in win7
- 精品方案|海泰方圆全栈式数据安全治理方案 为数据设一把“安全锁”
- DHCP experiment demonstration (Huawei switch device configuration)
- What is WordPress
- 微软安全团队发现一家利用Windows零日漏洞销售间谍软件的奥地利公司
- 好用到爆!IDEA 版 Postman 面世了,功能真心强大
- Display line number under VIM command [easy to understand]
- GIS数据漫谈(五)— 地理坐标系统
- 理解Oracle的几个概念
猜你喜欢

PHP发送移动MAS短信乱码的解决方法

What is WordPress

Two dimensional prefix and

Office2013 input mathematical formula above

好用到爆!IDEA 版 Postman 面世了,功能真心强大

ripro9.0修正升级版+WP两款美化包+稀有插件

精品方案|海泰方圆全栈式数据安全治理方案 为数据设一把“安全锁”

Machine learning strong foundation plan 0-5: why is the essence of learning generalization ability?

leetcode:1300. 转变数组后最接近目标值的数组和【二分】

18 diagrams, intuitive understanding of neural networks, manifolds and topologies
随机推荐
Microsoft security team found an Austrian company that used windows Zero Day vulnerability to sell spyware
DHCP experiment demonstration (Huawei switch device configuration)
DHCP实验演示(Huawei交换机设备配置)
Understanding of the return value of the structure pointer function passed to the structure pointer
STM32 drives st7701s chip (V ⅰ V0 mobile phone screen change price)
[FPGA tutorial case 41] image case 1 - reading pictures through Verilog
Learning notes tree array
Detailed explanations of%*d,%.*s, etc. of [C language]: "recommended collection"
【cesium】entity属性和时许绑定:SampledProperty方法简单使用
1331. 数组序号转换
ThinkPad指纹验证在win7无法使用的解决方法
Installation points and precautions of split angle probe
Understand several concepts of Oracle
理解Oracle的几个概念
Tiktok programmer confession special code tutorial (how to play Tiktok)
微软安全团队发现一家利用Windows零日漏洞销售间谍软件的奥地利公司
Why does MySQL sometimes choose the wrong index?
Nodejs: set up the express service, set up the session and realize the exit operation
用手机对电脑进行远程关机
什么是WordPress