Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何检测网站是否超载?_Php_Curl - Fatal编程技术网

Php 如何检测网站是否超载?

Php 如何检测网站是否超载?,php,curl,Php,Curl,我需要找到一种方法来检测网站(joseki端点)是否过载http://128.250.202.125:7001/joseki/oracle始终处于打开状态,但当我提交查询时,有时它处于空闲状态。(即过载,而不是停机) 到目前为止,我的方法是使用curl模拟表单提交。如果curl_exec返回false,我知道网站超载了 主要的问题是,我不确定网站过载是否会触发“假返回”。 我可以用这个来记录curl_exec的返回,但这会导致网站崩溃 <?php $is_run = true; if($

我需要找到一种方法来检测网站(joseki端点)是否过载<代码>http://128.250.202.125:7001/joseki/oracle始终处于打开状态,但当我提交查询时,有时它处于空闲状态。(即过载,而不是停机)

到目前为止,我的方法是使用curl模拟表单提交。如果curl_exec返回false,我知道网站超载了

主要的问题是,我不确定网站过载是否会触发“假返回”。 我可以用这个来记录curl_exec的返回,但这会导致网站崩溃

<?php

$is_run = true;
if($is_run) {
    $url = "http://128.250.202.125:7001/joseki/oracle";

    $the_query = "
PREFIX dc:    <http://purl.org/dc/elements/1.1/>
PREFIX rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd:   <http://www.w3.org/2001/XMLSchema#>
PREFIX owl:   <http://www.w3.org/2002/07/owl#>
PREFIX fn:    <http://www.w3.org/2005/xpath-functions#>
PREFIX ouext: <http://oracle.com/semtech/jena-adaptor/ext/user-def-function#>
PREFIX oext:  <http://oracle.com/semtech/jena-adaptor/ext/function#>
PREFIX ORACLE_SEM_FS_NS: <http://oracle.com/semtech#timeout=100,qid=123>
SELECT ?sc ?c
WHERE 
  { ?sc rdfs:subClassOf ?c} 
    ";

    // Simulate form submission.    
  $postdata = http_build_query(array('query' => $the_query));
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_POST, 1);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  $tmp_condi = curl_exec($curl);

    // After I submit a simulated form submission, and http://128.250.202.125:7001/joseki/oracle is
    // not responding (i.g. idling), does it definitely returns FALSE????
  if($tmp_condi === FALSE) {
    die('not responding');  
  }
    else {

    }

  curl_close($curl);
}
我需要找到一种方法来检测网站是否有响应。 到目前为止,我的方法是使用curl模拟表单提交

我宁愿执行httpheadrequest()并检查返回代码。您不需要返回任何数据,因此无需发送POST请求或获取响应。我还为请求设置了缩短超时:

$ch = curl_init();
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);

curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

$content = curl_exec($ch);
curl_close($ch);

如果
$http\u status
为200(正常),则远程端可能被视为处于活动状态。

是的,如果网站在一段时间内没有响应(在
CURLOPT\u CONNECTIONTIMEOUT
中设置),它将触发一个错误,
curl\u exec()
将返回
false
,事实上,对于任何其他错误,它也将返回
false
,因此,您的代码实际上无法判断站点是否已关闭。

您可以在curl\u exec之后使用
curl\u error($curl)
查看是否发生错误。@Asenar我已将日志记录到代码中,正在等待站点关闭。你看过没有回复的网站吗?curl_exec返回false?我为我的问题重写了。我为我的问题重写了。对不起,我甚至不明白我在问什么。
$ch = curl_init();
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);

curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

$content = curl_exec($ch);
curl_close($ch);