我有兩個服務器,一個是在其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 –