您的位置 首页 php

高性能、高灵活性的 PHP 协程框架,Hyperf 安装实操

目前协程的出现改变了很多PHP内容,各大框架也陆续结合协程实现了更丰富的内容。而且协程也衍生出很多优秀的框架。

~~出于学习的目的下面我将使用Hyperf创建一个自己的站点。~~


检查环境

Hyperf对环境有些要求。下面是官方给与的要求:

PHP >= 7.2

Swoole PHP 扩展 >= 4.5,并关闭了 Short Name

OpenSSL PHP 扩展

JSON PHP 扩展

PDO PHP 扩展 (如需要使用到 MySQL 客户端)

Redis PHP 扩展 (如需要使用到 Redis 客户端)

Protobuf PHP 扩展 (如需要使用到 gRPC 服务端或客户端)

首先在服务器查看自己的PHP版本

然后是 Swoole 扩展版本

 php --ri swoole  

JSON PHP 扩展 已经被内置到了PHP7.2中。不用再次安装。

Swoole PHP 扩展 >= 4.5,并关闭了 Short Name 这个要注意:需要手动在php.in中添加 swoole.use_shortname = off 关闭 Short Name.

OpenSSL PHP 扩展需要开启。

执行命令

 composer create-project hyperf/hyperf-skeleton  

然后在服务器网站目录下执行命令。将进行hyperf安装。

当然我们希望安装是一番丰顺的,但是并不是所有的安装都会正常运行。例如我就遇到了比较奇怪的问题。

 [root@ecs-c6s-large-2-linux-20200330161950 wwwroot]# composer create-project hyperf/hyperf
Creating a "hyperf/hyperf" project at "./hyperf"
Installing hyperf/hyperf (v2.0.25)
  - Installing hyperf/hyperf (v2.0.25): Extracting archive
Created project in /www/wwwroot/hyperf
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires PHP extension ext-redis * but it is missing from your system. Install or enable PHP's redis extension.
  Problem 2
    - league/flysystem[1.0.49, ..., 1.x-dev] require ext-fileinfo * -> it is missing from your system. Install or enable PHP's fileinfo extension.
    - xxtime/flysystem-aliyun-oss 1.5.0 requires league/flysystem ^1.0.49 -> satisfiable by league/flysystem[1.0.49, ..., 1.x-dev].
    - Root composer.json requires xxtime/flysystem-aliyun-oss ^1.5 -> satisfiable by xxtime/flysystem-aliyun-oss[1.5.0].

To enable extensions, verify that they are enabled in your .ini files:
    - /www/server/php/72/etc/php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.  

这里提示我需要开启PHP redis 扩展,和PHP fileinfo扩展。然而官网上说这个是非必须的。

解决问题

解决问题也比较简单。开启PHP redis 扩展,和PHP fileinfo扩展即可。我比较懒用的宝塔。宝塔开启PHP redis 扩展,和PHP fileinfo扩展 需要到宝塔PHP管理中的扩展管理开启相应内容即可。

这样我们就可以正常进行安装了。记得服务器可用内容要大于1g.不然PHP fileinfo扩展有可能安装不成功。


总结:

Hyperf 对环境要求还是有的。但是只要环境问题解决了。他的安装速度都是杠杠的。而且这点问题对应PHPer们就是张飞吃豆芽。小菜一碟。

文章来源:智云一二三科技

文章标题:高性能、高灵活性的 PHP 协程框架,Hyperf 安装实操

文章地址:https://www.zhihuclub.com/151686.shtml

关于作者: 智云科技

热门文章

网站地图