nginx/php-fpm
$servername = "";
$username = "root";
$password = "";
$dbname = "test";
// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// 检测连接
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
$sql = "INSERT INTO test (name, create_time) VALUES ('zhuyanbin', ". time()." )";
if ($conn->query($sql) === TRUE) {
#echo 'success';
} else {
#echo 'error';
}
$conn->close();
swoole
//高性能HTTP服务器
$http = new Swoole\Http\Server("0.0.0.0", 9501);
$http->on("start", function ($server) {
echo "success";
});
$http->on("request", function ($request, $response) {
#$swoole_mysql = new Swoole\Coroutine\MySQL();
#$swoole_mysql->connect([
#'host' => '',
#'port' => 3306,
#'user' => 'root',
#'password' => '',
#'database' => 'test',
#]);
#$sql = "INSERT INTO test (name, create_time) VALUES ('zhuyanbin', ". time()." )";
#$res = $swoole_mysql->query($sql);
#if ($res === false) {
#echo 'error';
#}
$response->header("Content-Type", "text/plain");
$response->end("Hello World\n");
});
$http->start();
测试服务器为腾讯云1G4核最低配服务器
在10个用户并发1000的状态下测试10次结果(有数据库操作)
nginx/php-fpm | swoole |
---|---|
17 | 18.3 |
16.4 | 16.9 |
16.3 | 16.7 |
16.9 | 17.5 |
16.4 | 17.0 |
17 | 16.8 |
16.3 | 16.8 |
17.7 | 17.3 |
16.1 | 18.1 |
16.5 | 16.7 |
平均值
nginx/php-fpm:16.6
swoole:17.2
在10个用户并发1000的状态下测试10次结果(无数据库操作)
nginx/php-fpm | swoole |
---|---|
6.4 | 6.2 |
7.4 | 6.1 |
8.3 | 6.1 |
6.4 | 6.2 |
6.6 | 6.1 |
6.3 | 7.8 |
6.4 | 6.1 |
7.2 | 6.9 |
6.3 | 6.2 |
6.4 | 6.8 |