網站名稱:ToolFk
工具链接:https://www.toolfk.com/tool-online-bench
代码教學
本工具[在线压力测试工具]依赖的代码库为 https://github.com/rakyll/hey
STEP 1
STEP 2
核心代码如下
#-n Number of requests to run. Default is 200.
$number_n = intval(request('n',200));
$number_n = $number_n>10000?10000:$number_n;
$number_n = $number_n<10?10:$number_n;
$cmd .= " -n {$number_n}";
#-c Number of requests to run concurrently. Total number of requests cannot be smaller than the concurrency level. Default is 50.
$number_c = intval(request('c',50));
$number_c = $number_c>1000?1000:$number_c;
$number_c = $number_c<10?10:$number_c;
$cmd .= " -c {$number_c}";
#Rate limit, in queries per second (QPS). Default is no rate limit. (速率限制)
$number_q = intval(request('q',0));
$number_q = $number_q>1000?1000:$number_q;
$number_q = $number_q<0?0:$number_q;
if($number_q){
$cmd .= " -q {$number_q}";
}
#-z 执行多久时间
$number_z = intval(request('z',0));//10s,3m
$number_z = $number_z>60?60:$number_z; #最多60s
$number_z = $number_z<0?0:$number_z;
if($number_z){
$cmd .= " -z {$number_z}";
}
#-m HTTP method, one of GET, POST, PUT, DELETE, HEAD, OPTIONS.
$number_m = request('m','GET');//GET,POST
if(!in_array($number_m,["GET","POST"])){
$number_m = "GET";
}
$cmd .= " -m {$number_m}";
# -t Timeout for each request in seconds. Default is 20, use 0 for infinite.
$number_t = intval(request('t',20));
$number_t = $number_t>60?60:$number_t; #最多60s
$number_t = $number_t<0?0:$number_t;
if($number_t){
$cmd .= " -t {$number_t}";
}
# -T Content-type, defaults to "text/html".
$number_T = request('T',"text/html");
if(!in_array($number_T,["text/html","application/json","multipart/form-data"])){
$number_T = "text/html";
}
$cmd .= " -T {$number_T}";
# -d HTTP request body.
$number_d = request('d');
if($number_m == "POST"){
$cmd .= " -d {$number_d}";
}
// \App\Helper\UtilsHelper::log_debug("CMD",$cmd);
$cmd .= " 2>&1";
$content = shell_exec($cmd);