首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >apachebench symfony2登录页面基准

apachebench symfony2登录页面基准
EN

Stack Overflow用户
提问于 2015-05-22 09:35:48
回答 1查看 249关注 0票数 1

我正在尝试对symfony应用程序进行基准测试,因此我还需要对仅限于登录用户的页面进行基准测试。

我希望使用apachebench工具对应用程序进行基准测试,因此编写了一个小的shell脚本,尝试使用curl登录,获取从请求返回的phpsessid,并在apachebench命令中将其设置为cookie。

下面是looks脚本的样子:

代码语言:javascript
复制
#!/bin/bash

COOKIE_JAR="/var/www/apachebench/test.jar"

curl -c $COOKIE_JAR --data "_email=admin%40dummy.at&_password=test&_target_path=%2Fbackend" http://symfony.local/login

PHPSESSID=$(cat $COOKIE_JAR | grep PHPSESSID | cut -f 7)

ab -n 10 -p /var/www/apachebench/albumpostfile.txt -T application/x-www-form-urlencoded -C PHPSESSID=$PHPSESSID -k  http://symfony.local/album/add

apachebench命令应该发布表单并将数据存储在数据库中。但是,看起来我没有登录,因为数据没有存储,在使用我从浏览器复制的PHPSESSID之前,我尝试了这个命令,它运行得非常好。我也已经在全球范围内禁用了csrf的保护。

我还检查了从curl返回的PHPSESSID是否正确地输入到ab命令中。

我完全不知道我做错了什么,因为我试图通过铬扩展“邮递员”将完全相同的数据发布到登录页面,并且在那里工作。

curl请求中的cookie-jar文件如下所示:

代码语言:javascript
复制
# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

symfony.local   FALSE   /       FALSE   0       PHPSESSID       t2glc67hlf6lrlik2ieg9r7rv7

提前谢谢。

编辑:,这是apachebench在向命令中添加-v 3时的输出

代码语言:javascript
复制
WARNING: Response code not 2xx (302)
LOG: header received:
HTTP/1.0 302 Found
Date: Fri, 22 May 2015 12:03:32 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.9
Cache-Control: private, must-revalidate
Location: http://symfony.local/login
pragma: no-cache
expires: -1
Connection: close
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="1;url=http://symfony.local/login" />

        <title>Redirecting to http://symfony.local/login</title>
    </head>
    <body>
        Redirecting to <a href="http://symfony.local/login">http://symfony.local/login</a>.
    </body>
</html>
WARNING: Response code not 2xx (302)
LOG: header received:
HTTP/1.0 302 Found
Date: Fri, 22 May 2015 12:03:32 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.9
Cache-Control: private, must-revalidate
Location: http://symfony.local/login
pragma: no-cache
expires: -1
Connection: close
Content-Type: text/html; charset=UTF-8

EDIT2:这是我的新shell脚本,我修改了它,使curl命令发送一个PHPSESSID及其请求。下面您可以看到两个脚本的不同输出。它看起来像第二个工作,因为它指出正确的url在重定向到Url部件。但是这一次apachebench命令根本没有做任何事情,它只是卡住了。

代码语言:javascript
复制
#!/bin/bash

COOKIE_JAR="/var/www/apachebench/test.jar"

#curl -c $COOKIE_JAR -v -d "_email=admin%40dummy.at&_password=test&_target_path=%2Fbackend" -b "PHPSESSID=1hrfrnud407n5j42oki13655g7" http://symfony.local/login
curl -c $COOKIE_JAR -v -d "_email=admin%40dummy.at&_password=test&_target_path=%2Fbackend" http://symfony.local/login

PHPSESSID=$(cat $COOKIE_JAR | grep PHPSESSID | cut -f 7)

ab -n 10 -p /var/www/apachebench/albumpostfile.txt -T application/x-www-form-urlencoded -C PHPSESSID=$PHPSESSID http://symfony.local/album/add

OLD-CURL-OUTPUT:

代码语言:javascript
复制
* Hostname was NOT found in DNS cache
*   Trying 127.0.1.1...
* Connected to symfony.local (127.0.1.1) port 80 (#0)
> POST /login HTTP/1.1
> User-Agent: curl/7.35.0
> Host: symfony.local
> Accept: */*
> Content-Length: 62
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 62 out of 62 bytes
< HTTP/1.1 302 Found
< Date: Fri, 22 May 2015 12:39:05 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.9
* Added cookie PHPSESSID="l2pfvtum211bd8tnpp1i0vpcj1" for domain symfony.local, path /, expire 0
< Set-Cookie: PHPSESSID=l2pfvtum211bd8tnpp1i0vpcj1; path=/
< Cache-Control: no-cache
< Location: http://symfony.local/login
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="1;url=http://symfony.local/login" />

        <title>Redirecting to http://symfony.local/login</title>
    </head>
    <body>
        Redirecting to <a href="http://symfony.local/login">http://symfony.local/login</a>.
    </body>
* Connection #0 to host symfony.local left intact
</html>

NEW-CURL-OUTPUT:

代码语言:javascript
复制
* Hostname was NOT found in DNS cache
*   Trying 127.0.1.1...
* Connected to symfony.local (127.0.1.1) port 80 (#0)
> POST /login HTTP/1.1
> User-Agent: curl/7.35.0
> Host: symfony.local
> Accept: */*
> Cookie: PHPSESSID=1hrfrnud407n5j42oki13655g7
> Content-Length: 62
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 62 out of 62 bytes
< HTTP/1.1 302 Found
< Date: Fri, 22 May 2015 12:40:07 GMT
* Server Apache/2.4.7 (Ubuntu) is not blacklisted
< Server: Apache/2.4.7 (Ubuntu)
< X-Powered-By: PHP/5.5.9-1ubuntu4.9
* Added cookie PHPSESSID="3ehl5ldkbd4ngl2er663899km1" for domain symfony.local, path /, expire 0
< Set-Cookie: PHPSESSID=3ehl5ldkbd4ngl2er663899km1; path=/
< Cache-Control: no-cache
< Location: http://symfony.local/backend
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=UTF-8
<
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="1;url=http://symfony.local/backend" />

        <title>Redirecting to http://symfony.local/backend</title>
    </head>
    <body>
        Redirecting to <a href="http://symfony.local/backend">http://symfony.local/backend</a>.
    </body>
* Connection #0 to host symfony.local left intact
</html>This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking symfony.local (be patient)...

输出的最后一行是ab命令被卡住的地方。

EN

回答 1

Stack Overflow用户

发布于 2015-05-23 11:51:05

我想出来了,现在起作用了。

第二个命令非常好,所以如果您对symfony进行基准测试,那么您确实需要将一个PHPSESSID传递给登录调用。

它挂在apachebench命令上的原因与shell脚本无关,而是因为代码中缺少一个{,我在调试它时不小心删除了它。通过查看apache2 error.log文件,我能够找到它。

因此,如果其他任何人都会遇到同样的问题,请记住在curl命令中添加一个PHPSESSID,登录就会正常工作,并且您可以对需要登录的页面进行基准测试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30393255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档