我有两个服务器,一个是在其PHP应用程序运行应用服务器上Mysql数据库运行另一台服务器。我想测量从应用程序服务器发送的请求所花费的时间,以请求在数据库服务器上收到执行任何查询的请求。确切的网络时间到MySQL数据库服务器
注意:在执行任何查询以响应请求之前,请求仅发送到数据库服务器和数据库服务器上接收到的请求时的时间戳。对在两台服务器之间传输数据所需的时间感兴趣。我知道这取决于数据的大小。我只想为那些不同规模的数据争取时间。
好心建议如果有这类来测量或做只此特定请求的任何方法,任何工具。(已经了解发送请求时间戳只需要知道如何捕捉请求获得时间戳)
任何人都可以建议做到这一点从一台机器上的PHP服务器到另一台机器上的MySQL数据库服务器。 并在数据库或文件的任何地方或任何可能有用的工具上记录该时间。 我到现在为止做的是上传任何文件从PHP服务器和记录时间之前执行MySQL查询,并试图获取数据库级别的时间戳时,它接收请求执行查询,但问题是,时间现在()我采取我不要以为是datasbase第一次被击中的时候。
代码是这样写的
<?php
include('db_config.php');
if (isset($_FILES['data'])) {
if (!file_exists('files/')) {
mkdir('files/', 0777, true);
}
if (!file_exists('img/')) {
mkdir('img/', 0777, true);
}
$errors = array();
$file_name = $_FILES['data']['name'];
$file_size = $_FILES['data']['size'];
$file_tmp = $_FILES['data']['tmp_name'];
$file_type = $_FILES['data']['type'];
if (move_uploaded_file($file_tmp, "img/" . $file_name)) {
$l = 1;
$t = microtime(true);
$micro = sprintf("%03d", ($t - floor($t)) * 1000);
$d = new DateTime(date('Y-m-d H:i:s.' . $micro, $t));
$dd = 'Receiving Time : ' . $d->format("Y-m-d H:i:s.u");
$fileSize = 'File Size : ' . $file_size;
$res = 'Sending Time : ' . $_REQUEST['hidd'] . ' ' . $dd . ' ' . $fileSize;
$directory = 'files/';
if (glob($directory . "*.txt") != false) {
$filecount = count(glob($directory . "*.txt"));
$filecount ++;
$file = "files/record_" . $filecount . ".txt";
$fd = fopen($file, "a");
if (!$fd) {
die("Could not open $file to write in");
}
fwrite($fd, $res);
} else {
$file = "files/record_" . $l . ".txt";
$fd = fopen($file, "a");
if (!$fd) {
die("Could not open $file to write in");
}
fwrite($fd, $res);
}
fclose($fd);
}
$db = new Database();
$db->connect();
echo $send_time = date("Y-m-d H:i:s");
$db->insert('request_record', array("$file_name", "$file_size", $send_time, "$res"), "file_name,
file_size,
request_generated_time,
file_uploaded
");
$res = $db->getResult();
print_r($res);
echo $end_time = date("Y-m-d H:i:s"); } ?>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data" id="frm1">
<input type="file" name="data" />
<input type="hidden" name="hidd" id="hd" />
<input type="button" value="Submit" onclick="pdfSubmit()"/>
</form>
</body>
<script type="text/javascript" src="./jquery-1.9.1.min.js"></script>
<script>
function pdfSubmit() {
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
var miliseconds = currentTime.getMilliseconds();
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
var year = pad(currentTime.getFullYear());
var month = pad(currentTime.getMonth() + 1);
var day = pad(currentTime.getDate());
var n = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds + '.' + miliseconds;
$('#hd').val(n);
$('#frm1').submit();
}
function pad(numb) {
return (numb < 10 ? '0' : '') + numb;
}
</script>
</html>
好心建议如何在数据库服务器上收到它的存储请求@devon –