Getting Started with Hyperf: Installation, Configuration, and Running the Swoole‑Based PHP Coroutine Framework
This guide introduces Hyperf, a high‑performance PHP coroutine framework built on Swoole, explains its CLI vs PHP‑FPM modes, lists required system extensions, shows how to configure Composer mirrors, install the skeleton, disable Swoole short names, start the server, and resolve common port‑conflict issues.
Hyperf is a high‑performance, highly flexible PHP coroutine framework based on Swoole 4.5+, offering a built‑in coroutine server and many reusable components that follow PSR standards and a powerful dependency‑injection design.
The framework can run in CLI mode, where the application stays resident in memory, or in the traditional PHP‑FPM mode, which re‑initialises the framework on every request; CLI mode provides a significant performance boost.
Environment requirements : Linux or macOS (Windows via Docker), PHP ≥ 7.3, Swoole ≥ 4.5 (short name disabled), OpenSSL, JSON, PDO (for MySQL), Redis, and Protobuf extensions.
Composer mirror configuration (optional for faster downloads) :
<code>composer config -g repo.packagist composer https://mirrors.aliyun.com/composer</code>Install Hyperf skeleton :
<code>composer create-project hyperf/hyperf-skeleton</code>After installation, edit php.ini to disable Swoole short names:
<code>[swoole]
extension = swoole.so
swoole.use_shortname = off</code>Start the project (run from the framework root or specify the bin path):
<code>php bin/hyperf.php start</code>Because Hyperf runs as a persistent CLI process, after modifying code you should stop the current process (Ctrl + C) and restart it with the same command.
Port conflict resolution :
<code>netstat -tunlp | grep 9501
kill 15893</code>Use the above commands to find the process listening on the configured port (default 9501) and terminate it before restarting Hyperf.
Finally, test the service by accessing http://<em>your‑ip</em>:9501 in a browser.
Summary : Setting up Hyperf requires a Linux/macOS (or Docker) environment, PHP ≥ 7.3 with several extensions, disabling Swoole short names, and running the CLI start command. Once configured, the framework offers far better performance than traditional PHP‑FPM frameworks.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.