Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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_Loops_Curl - Fatal编程技术网

对于php来说,测量连接时间是否是一种好的做法?有更好的办法吗?

对于php来说,测量连接时间是否是一种好的做法?有更好的办法吗?,php,loops,curl,Php,Loops,Curl,我需要连续多次测量一个Web服务的响应时间,我以前对一个连接(没有循环)这样做,但现在这样做感觉不合适,尽管它似乎可以工作。如有任何建议,将不胜感激 $servername = "x.x.x.x"; $username = "xxx"; $password = "xxx"; $db = "xxx"; for($i=0; $i<10;++$i){ $ch = $_SESSION['cURL']; $time_pre = microtime(true); $data = cur

我需要连续多次测量一个Web服务的响应时间,我以前对一个连接(没有循环)这样做,但现在这样做感觉不合适,尽管它似乎可以工作。如有任何建议,将不胜感激

$servername = "x.x.x.x";
$username = "xxx";
$password = "xxx";
$db = "xxx";

for($i=0; $i<10;++$i){

  $ch = $_SESSION['cURL'];
  $time_pre = microtime(true);
  $data = curl_exec($ch);
  $time_pro = microtime(true);
  $exec_time[$i] = $time_pro - $time_pre;
 }

$conn = mysqli_connect($servername, $username, $password, $db);

//Check connection
if ($conn->connect_error){
    die("Connection failed: " . $conn->connect_error);
}

date_default_timezone_set('Europe/Madrid');
$date = date('Y-m-d H:i:s');
var_dump($date);

for($i=0; $i<10;++$i){
    $query = "INSERT INTO DB(time, date) VALUES('$exec_time[$i]', '$date')";
    $result2=mysqli_query($conn, $query);
}
$servername=“x.x.x.x”;
$username=“xxx”;
$password=“xxx”;
$db=“xxx”;
对于($i=0;$iconnect\u错误){
die(“连接失败:”.$conn->connect\U错误);
}
日期默认时区设置(“欧洲/马德里”);
$date=日期('Y-m-d H:i:s');
var_dump(日期);

对于($i=0;$i我最终在评论中使用了劳伦斯·切龙的建议。它比我使用的更快更干净。


最后我在评论中使用了劳伦斯·切隆的建议,它比我使用的更快更干净。


我认为你的问题更适合代码审查::-)curl\u getinfo($ch)['total\u time'],还有10倍的curl\u multifaster@SketchyCoder我不知道那件事!我会尽快检查,如果是这样的话,我会改变问题。谢谢^^@LawrenceCherone卷曲多功能看起来很棒。如果你想把它作为回答,我会等几个小时让其他人回答,如果没有更好的答案,我会选择你的答案!我认为你的问题更适合代码审查::-)curl\u getinfo($ch)['total\u time'],还有10倍的curl\u multifaster@SketchyCoder我不知道那件事!我会尽快检查,如果是这样的话,我会改变问题。谢谢^^@LawrenceCherone卷曲多功能看起来很棒。如果你想把它作为回答,我会等几个小时让其他人回答,如果没有更好的答案,我会选择你的答案!
//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

$active = null;
//execute the handles
do {
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) != -1) {
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
}

//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);