PHP的snoopy第三方库怎么进行超时判断。
大家讲道理
大家讲道理 2017-04-10 16:07:11
0
1
614

因为URL不确定,需要判断url是否存在(是否超时),下面是自己写的

function s($url){
    $snoopy = new Snoopy();
    $snoopy->read_timeout = 5;
    $snoopy->fetch($url);
    if($snoopy->$timed_out === true){
        echo "超时了";
        return;
    }else{
        return $snoopy->response_code;
    }
}
echo s("http://zihonaini.com");

百度半天,也没找到相对应的事例

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

répondre à tous(1)
Ty80
$snoopy->read_timeout = x

update:

你应该关心status code是不是200,而不是失败的各种特列

$snoopy->read_timeout = x;
$snoopy->fetch($url);
if ($snoopy->status == 200) {
  // 成功
} else {
  // 失败
}

或者看这里的例子 http://dret.net/lectures/services-fall06/a/3/README.txt

if ($snoopy->fetch($url)) {
  // 成功
} else {
  // 失败
}

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!