Skip to content

Instantly share code, notes, and snippets.

@lbp0200
Last active August 29, 2015 14:18
Show Gist options
  • Save lbp0200/fca75e130cff6b862dd1 to your computer and use it in GitHub Desktop.
Save lbp0200/fca75e130cff6b862dd1 to your computer and use it in GitHub Desktop.
压力测试
<?php
function postcurl($curlPost) {
$ch = curl_init(); //初始化curl
curl_setopt($ch, CURLOPT_URL, 'http://host/index.php?url'); //抓取指定网页
//curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch); //运行curl
echo ($data);
curl_close($ch);
}
function unicode_decode($name) {
// 转换编码,将Unicode编码转换成可以浏览的utf-8编码
$pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
preg_match_all($pattern, $name, $matches);
if (!empty($matches)) {
$name = '';
for ($j = 0; $j < count($matches[0]); $j++) {
$str = $matches[0][$j];
if (strpos($str, '\\u') === 0) {
$code = base_convert(substr($str, 2, 2), 16, 10);
$code2 = base_convert(substr($str, 4), 16, 10);
$c = chr($code) . chr($code2);
$c = iconv('utf-16', 'UTF-8', $c);
$name .= $c;
} else {
$name .= $str;
}
}
}
return $name;
}
function createWords($words = 128) {
$seperate = array(",", "。", "!", "?", ";");
$strings = '';
for ($i = 0; $i < $words; $i++) {
$strings .= iconv('utf-16', 'utf-8', chr(rand(0x00, 0xFF)) . chr(rand(0x4E, 0x99)));
if (fmod($i, 18) > rand(10, 20)) {
$strings .= $seperate[rand(0, 4)];
}
}
return $strings;
}
for ($i = 0; $i < 5; $i++) {
$a = $i + 1;
$tmp = createWords(rand(1, 21));
postcurl("<xml><ToUserName><![CDATA[gh_f936345dc4e8]]>
</ToUserName><FromUserName><![CDATA[oBs8ws5zzYmliYqASCHfufP15TDk]]></FromUserName>
<CreateTime>time()</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[$tmp]]></Content><MsgId>6119707894490032057</MsgId></xml>");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment