0%

如何单独测试 Yar Server

单独压测/测试 Yar Server.

本章主要记录 ab 压测 Yar Server, curl 测试 Yar Server.

Yar_Client.php

1
2
3
4
<?php
$client = new Yar_Client('http://www.local.com/separate_test_yar_server/Yar_server.php');

echo '<pre>'; var_dump($client->get('codezm')); echo '</pre>'; die();

Yar_Server.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
class API {
/**
* the doc info will be generated automatically into service info page.
* @params
* @return
*/
public function get($parameter, $option = "foo") {
return array(
'parameter' => $parameter,
'option' => $option
);
}

protected function client_can_not_see() {
}
}

//file_put_contents('Yar_client_request_header.dump', var_export($_SERVER, true) . "\n" . var_export(@$_POST, true) . "\n" . var_export(@$_GET, true), FILE_APPEND);

//file_put_contents('Yar_client_request_post_data.dump', file_get_contents('php://input'), FILE_APPEND);

$service = new Yar_Server(new API());
$service->handle();

首先, 记录一下 Yar_Client 请求到 Yar_Server 的请求头及请求数据.

1
curl http://www.local.com/separate_test_yar_server/Yar_Client.php

关闭 Yar_Server 端文件记录语句, 准备进行测试.

Curl 测试.

1
2
3
4
curl --user-agent "PHP Yar Rpc-2.0.2" \
-H 'Content-Type:application/x-www-form-urlencoded' \
--data-binary @Yar_client_request_post_data.dump \
http://www.local.com/separate_test_yar_server/Yar_Server.php

Ab 压测.

1
2
3
4
5
ab -H 'user-agent:PHP Yar Rpc-2.0.2' \
-T 'application/x-www-form-urlencoded' \
-p ./Yar_client_request_post_data.dump \
-c 1000 -n 10000 \
http://www.local.com/separate_test_yar_server/Yar_Server.php

THE END.

Tips:
若需要完整代码可点击 此处 浏览并下载.