通过 curl模拟访问网站,接着进行sql查询,计算出时间戳
code :
-
<?php
-
date_default_timezone_set('UTC');
-
-
function Curlweb($url) {
-
$ch = curl_init();
-
curl_setopt($ch, CURLOPT_URL, $url);
-
curl_setopt($ch, CURLOPT_HEADER, 0);
-
curl_exec($ch);
-
curl_close($ch);
-
}
-
-
//微秒函数
-
function microtime_float()
-
{
-
list($usec, $sec) = explode(" ", microtime());
-
return ((float)$usec + (float)$sec);
-
}
-
-
-
function Connectdb($num,$add,$user) {
-
while($num<=100){
-
$time_start = microtime_float();
-
-
// 先 curl 一下 Web 页面,模拟用户请求数据
-
Curlweb('');
-
$conn = mysql_connect($add,$user);
-
-
if (!$conn) {
-
die('Could not connect: ' . mysql_error());
-
}
-
//connect success select
-
echo "Connected successfully\n\n";
-
-
mysql_select_db("syslog");
-
$sql = "select * from systemevents where Message like '%ssh %'";
-
$result = mysql_query($sql);
-
-
if($result) {
-
echo 'sql语句:' . $sql . '已经成功执行!';
-
$n = mysql_num_rows($result);
-
echo "$n\n";
-
}
-
mysql_close($conn);
-
sleep(0.5);
-
$num++;
-
-
$time_end = microtime_float();
-
$time = ($time_end - $time_start) * 1000;
-
$tmp = sprintf("%5.2f",$time);
-
echo $tmp."\t毫秒\n";
-
-
}
-
}
-
Connectdb('1' , '127.0.0.1' , 'root');
-
?>
阅读(2799) | 评论(0) | 转发(0) |