一 hyperf 是啥,有什么特点,安装hyperf

397 阅读1分钟

一 是啥

Hyperf 是一个高性能、高灵活性的渐进式 PHP 协程框架,内置协程服务器及大量常用的组件,性能较传统基于 PHP-FPM 的框架有质的提升

设计理念

Hyperspeed + Flexibility = Hyperf,从名字上我们就将 超高速 和 灵活性 作为 Hyperf 的基因。

  • 对于超高速,我们基于 Swoole 协程并在框架设计上进行大量的优化以确保超高性能的输出。
  • 对于灵活性,我们基于 Hyperf 强大的依赖注入组件,组件均基于 PSR 标准 的契约和由 Hyperf 定义的契约实现,达到框架内的绝大部分的组件或类都是可替换的。

三 安装hyperf

安装swoole .略. 安装后验证一下是否已安装. php -m |grep swoole swoole.

composer create-project hyperf/hyperf-skeleton

网速慢建议科学上网。

四 启动.

cd hyperf-skeleton php bin/hyperf.php start 万一端口被占就 netstat -anp|grep "9999" 然后kill 掉进程 。

五 测试访问 。

<?php
//app\Controller\IndexController.php
declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace App\Controller;
use Hyperf\DbConnection\Db;

class IndexController extends AbstractController
{
    public function index()
    {
        $method = $this->request->getMethod();
        $user = $this->request->input('user', 'Hyperf');

        $driver = env('DB_DRIVER', 'getDbDriver');
        return [
            'method' => $method,
            'message' => "Hello2 {$user}.",
            "env" => $driver
        ];
    }
}

curl 127.0.0.1:9501

{"method":"GET","message":"Hello2 Hyperf.","env":"mysql"}