<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OurApache &#187; apachebench</title>
	<atom:link href="http://ourapache.com/archives/tag/apachebench/feed" rel="self" type="application/rss+xml" />
	<link>http://ourapache.com</link>
	<description>我们致力于一个Apache知识的分享网站</description>
	<lastBuildDate>Tue, 13 Apr 2010 05:18:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>使用apachebench进行post压力测试</title>
		<link>http://ourapache.com/archives/17</link>
		<comments>http://ourapache.com/archives/17#comments</comments>
		<pubDate>Mon, 29 Dec 2008 02:42:20 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache初级应用]]></category>
		<category><![CDATA[ab]]></category>
		<category><![CDATA[apachebench]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[压力]]></category>
		<category><![CDATA[性能测试]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=17</guid>
		<description><![CDATA[apachebench网上的资料很多,但是甚至包括国外的文章以及官方文档,出了help显示的内容之外就没有任何一丁点更详细些的内容了]]></description>
			<content:encoded><![CDATA[<p>apachebench网上的资料很多<br />
但是甚至包括国外的文章以及官方文档<br />
出了help显示的内容之外就没有任何一丁点更详细些的内容了<br />
要使用ab进行post数据测试.从help可以看出我们需要定义两个内容<br />
一个是-p参数.指定需要post的数据<br />
还有一个是-T参数,指定使用的content-type<br />
我在服务器端简单的写了一个脚本.将获取到的post请求输出到文件</p>
<div class="hl-surround">
<div class="hl-main"><span style="color: blue;">&lt;?php</span><span style="color: gray;"><br />
</span><span style="color: green;">echo</span><span style="color: gray;"> </span><span style="color: #00008b;">$_REQUEST</span><span style="color: olive;">[</span><span style="color: #8b0000;">'</span><span style="color: red;">test</span><span style="color: #8b0000;">'</span><span style="color: olive;">]</span><span style="color: gray;">;<br />
</span><span style="color: #00008b;">$file</span><span style="color: gray;">=</span><span style="color: blue;">fopen</span><span style="color: olive;">(</span><span style="color: #8b0000;">&#8216;</span><span style="color: red;">/data/www/log.txt</span><span style="color: #8b0000;">&#8216;</span><span style="color: gray;">,</span><span style="color: #8b0000;">&#8216;</span><span style="color: red;">a+</span><span style="color: #8b0000;">&#8216;</span><span style="color: olive;">)</span><span style="color: gray;">;<br />
</span><span style="color: blue;">fwrite</span><span style="color: olive;">(</span><span style="color: #00008b;">$file</span><span style="color: gray;">,</span><span style="color: blue;">date</span><span style="color: olive;">(</span><span style="color: #8b0000;">“</span><span style="color: red;">Y-m-d H:i:s</span><span style="color: #8b0000;">“</span><span style="color: olive;">))</span><span style="color: gray;">;<br />
</span><span style="color: blue;">fwrite</span><span style="color: olive;">(</span><span style="color: #00008b;">$file</span><span style="color: gray;">,</span><span style="color: #00008b;">$_REQUEST</span><span style="color: olive;">[</span><span style="color: #8b0000;">'</span><span style="color: red;">test</span><span style="color: #8b0000;">'</span><span style="color: olive;">])</span><span style="color: gray;">;<br />
</span><span style="color: blue;">fclose</span><span style="color: olive;">(</span><span style="color: #00008b;">$file</span><span style="color: olive;">)</span><span style="color: gray;">;<br />
</span><span style="color: blue;">?&gt;</span></div>
</div>
<p>然后在本地生成post.txt文件<br />
内容为test=abc<br />
使用ab进行测试<br />
<a href="http://ourapache.com/archives/tag/ab" class="st_tag internal_tag" rel="tag" title="标签 ab 下的日志">ab</a> -n 1 -p <a href="http://ourapache.com/archives/tag/post" class="st_tag internal_tag" rel="tag" title="标签 post 下的日志">post</a>.txt http://192.168.0.2/test.php<br />
发现服务器端接受到了请求,但是没有受到post的数据<br />
使用类型之后.也还是不行<br />
ab -n 1 -p post.txt -T ‘text/html’ http://192.168.0.2/test.php<br />
使用get方式测试<br />
ab -n 1 http://192.168.0.2/test.php?test=abc<br />
服务器端则可以正常工作<br />
和开始说的一样.翻烂了google也没有找到<br />
最后只能用wireshark抓包<br />
最后发现content-type一定要设置成为<br />
application/x-www-form-urlencoded<br />
最后如下测试.才最后通过<br />
ab -n 1 -p post.txt -T ‘application/x-www-form-urlencoded’ http://192.168.0.2/test.php<br />
还有postfile<br />
如果有多条记录<br />
内容可以写成</p>
<div class="hl-surround">
<div class="hl-main">test1=a&amp;test2=b</div>
</div>
<p>类似这样即可<br />
这个也是文档中没有提及的,让我一开始以为postfile的格式有误.<br />
网上有提到过一种格式</p>
<div class="hl-surround">
<div class="hl-main">test1=a<br />
test2=b</div>
</div>
<p>这种是不对的<br />
这样的ab会把整个</p>
<div class="hl-surround">
<div class="hl-main">a回车test2=b</div>
</div>
<p>当作test1这个field传送出去</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年02月25号 -- <a href="http://ourapache.com/archives/168" title="apache ab压力测试收藏">apache ab压力测试收藏</a></li></ul>
	标签：<a href="http://ourapache.com/archives/tag/ab" title="ab" rel="tag">ab</a>, <a href="http://ourapache.com/archives/tag/apachebench" title="apachebench" rel="tag">apachebench</a>, <a href="http://ourapache.com/archives/category/primary" title="Apache初级应用" rel="tag">Apache初级应用</a>, <a href="http://ourapache.com/archives/tag/post" title="post" rel="tag">post</a>, <a href="http://ourapache.com/archives/tag/%e5%8e%8b%e5%8a%9b" title="压力" rel="tag">压力</a>, <a href="http://ourapache.com/archives/tag/%e6%80%a7%e8%83%bd%e6%b5%8b%e8%af%95" title="性能测试" rel="tag">性能测试</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/17/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

