http服务

http组件是当SERVER_TYPEEASYSWOOLE_WEB_SERVER自动启用的组件,它实现了控制器连接池,url解析以及url路由规则.
http组件demo

命名空间

我们首先需要在composer.json中注册应用目录的命名空间(控制器命名空间默认为App\HttpController)

  1. {
  2. "require": {
  3. "easyswoole/easyswoole": "^3.1"
  4. },
  5. "autoload": {
  6. "psr-4": {
  7. "App\\": "App/"
  8. }
  9. }
  10. }

然后更新一下composer

  1. composer update

默认控制器

创建App/HttpController/Index.php文件:

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Tioncico
  5. * Date: 2019/4/11 0011
  6. * Time: 14:40
  7. */
  8. namespace App\HttpController;
  9. use EasySwoole\Http\AbstractInterface\Controller;
  10. class Index extends Controller{
  11. function index()
  12. {
  13. $this->response()->write('hello world');
  14. // TODO: Implement index() method.
  15. }
  16. }

启动easyswoole:

  1. php easyswoole start

访问ip:9501,即可看到输出”hello world”;