apachebench symfony2登录页面基准

apachebench symfony2登录页面基准,symfony,curl,apachebench,Symfony,Curl,Apachebench,我正在尝试对symfony应用程序进行基准测试,因此我还需要对仅限于登录用户的页面进行基准测试 我想使用apachebench工具对应用程序进行基准测试,因此编写了一个小的shell脚本,该脚本尝试使用curl登录,获取从请求返回的phpsessid,并在apachebench命令中将其设置为cookie 以下是shellscript的外观: #!/bin/bash COOKIE_JAR="/var/www/apachebench/test.jar" curl -c $COOKIE_JAR

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

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

以下是shellscript的外观:

#!/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命令中,并且它是正确的

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

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

# 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
提前谢谢

编辑: 这是我在命令中添加-v3时apachebench的输出

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
旧卷曲输出:

新输出:


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

我找到了它,现在它正在工作

#!/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
第二个命令非常好,因此如果您对symfony进行基准测试,您确实需要将PHPSESSID cookie传递给登录调用

它挂起在apachebench命令上的原因与shell脚本无关,而是由于代码中缺少{,我在调试它时意外删除了该代码。通过查看apache2 error.log文件,我能够找到它


因此,如果其他人也会遇到同样的问题,请记住向curl命令中添加PHPSESSID cookie,登录将正常工作,您可以对需要登录的页面进行基准测试。

可能会出现一些错误。尝试将-v3添加到ab命令中,看看rterned是什么html。可能会对您有所帮助。我将在回答中发布响应,因为它是l我想听听你的意见
* 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>
* 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)...