Hyperf beginner installation to start and access!

小生我怕怕啊
Release: 2023-04-09 18:00:02
Original
10576 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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

php bin/hyperf.php start
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template