Php 通过使用bash脚本生成的动态url进行台架测试
我想使用Sakege用1M请求测试我的网站,不同的URL使用Sakege,我需要知道我可以创建一个bash脚本来执行随机循环,或者创建php脚本来从数据库读取URL并创建动态URL,并将此URL提供给Sakege命令来执行测试吗 例如,我有这种类型的横幅尺寸:Php 通过使用bash脚本生成的动态url进行台架测试,php,bash,terminal,apachebench,siege,Php,Bash,Terminal,Apachebench,Siege,我想使用Sakege用1M请求测试我的网站,不同的URL使用Sakege,我需要知道我可以创建一个bash脚本来执行随机循环,或者创建php脚本来从数据库读取URL并创建动态URL,并将此URL提供给Sakege命令来执行测试吗 例如,我有这种类型的横幅尺寸: [ { "id": 1, "size": "normal_x970h90", }, { "id": 2, "size": "normal_x234h6
[
{
"id": 1,
"size": "normal_x970h90",
},
{
"id": 2,
"size": "normal_x234h60",
},
{
"id": 3,
"size": "normal_x468h60",
},
{
"id": 4,
"size": "normal_x300h600",
},
{
"id": 5,
"size": "normal_x120h600",
},
{
"id": 6,
"size": "normal_x160h600",
},
{
"id": 7,
"size": "normal_x120h240",
},
{
"id": 8,
"size": "normal_x300h250",
},
{
"id": 9,
"size": "normal_x250h250",
},
{
"id": 10,
"size": "normal_x600h300",
},
{
"id": 11,
"size": "normal_x728h90",
},
{
"id": 12,
"size": "normal_x300h100",
},
{
"id": 13,
"size": "normal_x125h125",
}
]
我还有这些身份证:
[
0 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#915}
]
1 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#926}
]
2 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#924}
]
3 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#913}
]
4 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#929}
]
5 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#862}
]
6 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#863}
]
7 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#864}
]
8 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#865}
]
9 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#928}
]
10 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#927}
]
11 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#917}
]
12 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#918}
]
13 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#899}
]
14 => array:1 [
"_id" => MongoDB\BSON\ObjectID {#898}
]
]
我需要使用上述信息创建这些类型的url:
www.example.come/api/is/normal_x234h60/899
www.example.com/api/is/normal_x600h300/898
更像这样
有没有办法创建此URL并将其放入txt文件,然后运行我的命令:
siege -c10000 -b -t30m -f urls.txt
siege -c10000 -b -t30m -f urls.txt
或者使用apache ab bench test?我找到了解决方案,我创建了一个php文件,它连接到mysql和mongodb数据库并读取数据,然后在一个嵌套的for循环中创建了我需要的URL,并将它们存储在txt文件中。 然后我只需要运行攻城命令:
siege -c10000 -b -t30m -f urls.txt
siege -c10000 -b -t30m -f urls.txt
但由于大型请求的问题,我创建了一个bash脚本,它将读取每行url.txt文件,并使用每个url运行apache ab测试,以对我的应用程序的动态url进行压力测试
创建URL的php代码:
$seats = Seat::where('status', 'ACTIVE')->get();
$s_count = Seat::where('status', 'ACTIVE')->count();
$bs = Banners::where('status', 'enable')->get();
$bs_count = Banners::where('status', 'enable')->count();
$url = Config('conf.APP_PATH') . "/api/is/";
$url_array = array();
for ($i = 0; $i < $s_count; $i++) {
for ($j = 0; $j < $bs_count; $j++) {
$url_array[] = $url . $bs[$j]['size'] . "/" . $seats[$i]['_id']."\n";
}
}
File::put('./url.txt',$url_array);
运行多台测试的bash脚本:
while read LINE; do
cmnd="./ab -n10000 -c100 "
cmnd=${cmnd}"$LINE"
eval $cmnd
cmnd=''
done < urls.txt