ecs 實例 :swoole安裝與測試

安裝

1 使用pecl 安裝

命令:

pecl install swoole

錯誤1:

ERROR: `phpize’ failed
解決辦法:

yum install m4 autoconf

2 激活swoole擴展

php.ini 添加

extension=swoole.so

3 測試

http_server.php

<?php
$http = new Swoole\Http\Server("0.0.0.0",9502);

$http->on('request', function ($request, $response) {
    var_dump($request->get, $request->post);
    $response->header("Content-Type", "text/html; charset=utf-8");
    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});

$http->start();

服務器端運行:

php http_server.php

瀏覽器發送http請求

http://域名:9502/?a=11

結果:

array(1) {
  ["a"]=>
  string(2) "11"
}
NULL
NULL
NULL
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章