1. 程式人生 > >Swoole中內建Http伺服器

Swoole中內建Http伺服器

建立httpServer.php檔案,程式碼如下:

<?php

// 建立服務物件
$http = new swoole_http_server("10.211.55.17", 9501);   // 10.211.55.17是我們Swoole主機 9501是埠

// 監聽request請求
$http->on('request', function ($request, $response) {
    $response->end("<h1>Hello Swoole. #".rand(1000, 9999)."</h1>");
});

// 這一步很重要
$http->start();

2、上面程式碼就是swool中 http服務程式碼,執行檔案 開啟服務

php httpServer.php
Hello Swoole. #隨機數字

說明這個http服務的可以正常訪問的。