search
HomeBackend DevelopmentPHP TutorialHyperf beginner installation to start and access!

Hyperf’s official introduction:

Hyperf is a high-performance, highly flexible PHP coroutine framework based on Swoole 4.5, with built-in coroutine servers and a large number of commonly used The performance of components has been qualitatively improved compared to the traditional framework based on PHP-FPM. It provides ultra-high performance while maintaining extremely flexible scalability. Standard components are implemented based on the PSR standard and are based on powerful dependency injection design, ensuring Most components or classes are replaceable and reusable.

Hyperf runs in command line Cli mode. PHP-FPM mode is our commonly used mode. Among them, ThinkPHP, Laravle, Ci and other frameworks are all in this mode. The latest versions of TP and Laravle also support it. Cli mode!

Recommended: "PHP Video Tutorial"

The biggest difference between the two modes is:

PHP-FPM Yes: Every time you respond to a request, you must initialize the framework from the entry file, forward it to the controller through routing, get the result, and return the response!

Cli is: After starting the framework, the framework will reside in memory. Once started, it will register the service to the system, listen to our web port (80 or 9501, etc. can be customized), and then respond to every request. There is no need to load the framework file, the routing is recognized directly to the controller and you execute the logic code and return the result!

So the performance of the Hyperf framework is much higher than that of traditional frameworks such as TP. You only need to load it once and it will be waiting for you downstairs. One is that every time you look for him, he will come down from upstairs to see you every time.

Hyperf environment requirements:

Hyperf can only run in Linux and Mac environments, which means that our Windos computer does not support it, but Docker can be used under Windows for Windows as the running environment.

Running environment requirements:

  • PHP >= 7.3

  • ##Swoole PHP extension >= 4.5, and close Short Name

  • OpenSSL PHP extension

  • JSON PHP extension

  • PDO PHP extension (such as Need to use MySQL client)

  • Redis PHP extension (if need to use Redis client)

  • Protobuf PHP extension (if need to use To the gRPC server or client)

Hyperf installation:

You need to use composer, if your composer uses a foreign image , then it is very slow. Here is a very fast mirror address:

composer mirror address

composer config -g repo.packagist composer https://mirrors.aliyun.com/composer

Hyperf installation composer command

There are a series of steps during the installation process When asking, just press Enter to skip. They always ask you whether to install various components. We can skip them. If you need to use them in the future, just install them according to the commands in the document!

composer create-project hyperf/hyperf-skeleton

The installation of the Hyperf framework is now complete, but there is another pitfall that needs attention. The Short Name of swoole must be turned off!

Add

swoole.use_shortname = off below extension = swoole.so. The example is as follows:

[swoole]
extension = swoole.so
swoole.use_shortname = off

Start the project :

To start the project, you need to find the bin directory in the framework root directory, which contains a hyperf.php file

Execute the command in the framework bin directory:

php hyperf.php start

If you are in the framework root directory, you need to bring the bin path:

php bin/hyperf.php start

Since Hyperf is a persistent CLI framework, after you modify your code, terminate the currently started process instance through CTRL C and re-execute php bin/hyperf.php start to start the command.

What should I do if the port is occupied?

If after starting, you find that the port is occupied when starting here later, then check the port process ID, kill the process and start again!

<p>netstat -tunlp | grep 9501<br/>tcp  0  0 0.0.0.0:9501    0.0.0.0:*   LISTEN 15893/skeleton.Mast<br/>kill 15893</p>

netstat -tunlp | grep 9501 is the process of querying port 9501

kill 15893 is the process of killing 15893

Test access after the framework is started: http://ip: Port

Assume the server IP is: 47.33.112.136

Assume the port is: 9501

Then the access address is: http://47.33.112.136:9501

At this point, we have completed the installation, startup and access of the framework!

Summary:

Generally speaking, the process is not difficult. You need to have a learning server, or a mac computer itself, or a Docker environment built on a windows computer. . The requirement for PHP is greater than 7.3. It is recommended that you use PHP7.4. The extensions required for running also need to be installed together. The last step is to add swoole.use_shortname = off in php.ini, otherwise the framework cannot be started!

The above is the detailed content of Hyperf beginner installation to start and access!. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何使用Hyperf框架进行文件下载如何使用Hyperf框架进行文件下载Oct 21, 2023 am 08:23 AM

如何使用Hyperf框架进行文件下载引言:在使用Hyperf框架开发Web应用程序时,文件下载是一个常见的需求。本文将介绍如何使用Hyperf框架进行文件下载,包括具体的代码示例。一、准备工作在开始之前,确保你已经安装好了Hyperf框架并成功创建了一个Hyperf应用程序。二、创建文件下载控制器首先,我们需要创建一个控制器来处理文件下载的请求。打开终端,进

PHP Hyperf微服务开发指南:从入门到精通PHP Hyperf微服务开发指南:从入门到精通Sep 12, 2023 am 10:31 AM

从2004年诞生至今,PHP一直是全球最流行的开发语言之一。随着互联网的快速发展和技术的不断创新,PHP的发展也日新月异。其中,微服务架构逐渐成为当今软件开发的热门趋势。本文将带你进入PHPHyperf微服务开发的世界,从入门到精通。一、什么是微服务架构?微服务架构是一种基于一组小型、独立部署的服务组件构建的系统架构。相比于传统的单体应用架构,微服务架构通

如何使用Hyperf框架进行请求限流如何使用Hyperf框架进行请求限流Oct 20, 2023 pm 01:58 PM

如何使用Hyperf框架进行请求限流引言:在现代互联网应用中,如何在高并发的情况下保证系统的稳定性是非常重要的。请求限流是常见的应对策略之一。本文将介绍如何使用Hyperf框架进行请求限流,并给出具体的代码示例。一、什么是请求限流请求限流是指在一段时间内限制系统的请求访问量,避免系统因为过多的请求而崩溃。通过合理的限流策略,可以提供更好的服务质量和稳定性。H

如何使用Hyperf框架进行图片处理如何使用Hyperf框架进行图片处理Oct 24, 2023 pm 12:04 PM

如何使用Hyperf框架进行图片处理引言:随着移动互联网的快速发展,图片处理在现代Web开发中变得愈发重要。Hyperf是一款基于Swoole的高性能框架,它提供了丰富的组件和功能,包括图片处理。本文将介绍如何使用Hyperf框架进行图片处理,并提供具体的代码示例。一、安装Hyperf框架:在开始之前,我们先确保已经安装了Hyperf框架。可以通过Compo

如何使用Hyperf框架进行数据分页如何使用Hyperf框架进行数据分页Oct 20, 2023 am 11:25 AM

如何使用Hyperf框架进行数据分页引言:数据分页在实际的Web开发中非常常见,通过分页可以让用户浏览大量数据时更加便捷。Hyperf是一个高性能的PHP框架,提供了一系列强大的特性和组件。本文将介绍如何使用Hyperf框架进行数据分页,并给出详细的代码示例。一、准备工作:在开始之前,需要确保已经正确安装和配置了Hyperf框架。可以通过Composer进行

如何使用Hyperf框架进行缓存管理如何使用Hyperf框架进行缓存管理Oct 21, 2023 am 08:36 AM

如何使用Hyperf框架进行缓存管理缓存是提高应用性能的重要手段之一,而现代框架为我们提供了更加便捷的缓存管理工具。本文将介绍如何使用Hyperf框架进行缓存管理,并提供具体的代码示例。Hyperf框架是一款基于Swoole拓展开发的高性能框架,内置了丰富的组件和工具,其中包括强大的缓存管理功能。Hyperf框架支持多种缓存驱动,如Redis、Memcach

构建可扩展的微服务应用:探索PHP Hyperf的技术特点构建可扩展的微服务应用:探索PHP Hyperf的技术特点Sep 11, 2023 pm 07:01 PM

近年来,微服务架构已成为构建现代应用程序的主流方式。它通过将一个大型应用拆分成小而自治的服务,从而提高了应用的可扩展性、可维护性和可部署性。在微服务架构中,每个服务都是独立开发、部署和运行的,它们之间通过轻量级的通信机制进行交互。在构建微服务应用时,选择一个适合的开发框架非常关键。PHPHyperf是一个基于Swoole高性能协程网络框架的微服务框架

如何使用Hyperf框架进行Excel导入导出如何使用Hyperf框架进行Excel导入导出Oct 25, 2023 pm 12:13 PM

如何使用Hyperf框架进行Excel导入导出摘要:本文将介绍如何在Hyperf框架中实现Excel文件的导入和导出功能,并给出了具体的代码示例。关键字:Hyperf框架、Excel导入、Excel导出、代码示例导入首先,我们需要确保项目中安装了phpoffice/phpspreadsheet这个库。可以通过在终端中执行以下命令进行安装:composer

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft