CentOS 7 搭建 Swoole HTTP Server 教程
在 CentOS 7 上搭建 Swoole HTTP Server 可以按照以下步骤进行:
- 安装 PHP 和 Swoole 扩展:
yum install php php-devel php-pear -y
pecl install swoole
- 创建一个 PHP 文件,示例代码如下:
<?php
$http = new Swoole\Http\Server('0.0.0.0', 9501);
$http->on('start', function ($server) {
echo 'Swoole http server is started at http://0.0.0.0:9501\n';
});
$http->on('request', function ($request, $response) {
$response->header('Content-Type', 'text/plain');
$response->end('Hello World\n');
});
$http->start();
- 启动 swoole_http_server:
php /path/to/your/php/file.php
- 访问 http://your_ip_address:9501,即可看到输出的‘Hello World’信息。
注意:在生产环境中,建议使用 supervisor 等工具将 swoole_http_server 作为后台服务运行。
原文地址: https://www.cveoy.top/t/topic/mX0d 著作权归作者所有。请勿转载和采集!