Skip to content

Latest commit

 

History

History
137 lines (102 loc) · 8.69 KB

README_en.md

File metadata and controls

137 lines (102 loc) · 8.69 KB

中文 | English

workbunny

workbunny/webman-coroutine

🐇 Webman Coroutine Infrastructure Suite Compatible with Workerman. 🐇

Webman Coroutine Infrastructure Suite Compatible with Workerman.

Build Status Codecov Latest Stable Version PHP Version Require License

This document was translated by AI. If there are any inaccuracies or if any part is unclear, please refer to the original Chinese document or email for clarification. Corrections to the document are welcome.

Introduction

🚀🐇 webman-coroutine is a coroutine infrastructure support plugin for the workerman/webman development framework ecosystem

Origin

  • Workerman 4.x and the webman framework based on it as a runtime container do not support coroutines
  • Workerman 5.x and the webman framework based on it as a runtime container do not have complete coroutine capabilities
  • There is no unified way to use coroutines in workerman/webman, leading to high development and trial costs when switching coroutine drivers
  • Implementing coroutine versions of workers and servers on your own has high development and trial costs

The origin of the workbunny/webman-coroutine plugin and coroutine development sharing

Purpose

Vision

  1. Provide a simple coroutine toolkit in the workerman/webman development environment to reduce cognitive load.
  2. Attempt to implement a solution in the workerman/webman development environment that is compatible with both coroutine and non-coroutine development, making it easier to choose and abandon solutions, reducing anxiety.
  3. Try to achieve non-intrusive coroutine modifications to official components in the workerman/webman development environment (although it’s difficult, we want to try).
  4. Hope to provide some help, or even inspiration, to more PHP developers with the implementation of our code.

Installation

Install via composer:

composer require workbunny/webman-coroutine

Directory

|-- config                       # webman configuration files
|   |-- plugin
|   |-- webman-coroutine
|       |-- app.php          # main configuration
|       |-- process.php      # start process
|-- Events                       # workerman-4.x event-driven files
|-- Exceptions                   # exceptions
|-- Handlers                     # main driver entry
|-- Utils                        # toolkit
|   |-- Channel                  # channel driver
|   |-- Coroutine                # coroutine driver
|   |-- WaitGroup                # wait group driver
|   |-- Worker                   # worker driver
|   |-- Pool                     # object pool driver
|   |-- RegisterMethods.php      # driver registration helper
|-- Factory                      # entry class
|-- CoroutineWebServer.php       # custom http server for webman
|-- helpers.php                  # entry helper

Helper Functions

  • event_loop() used to automatically determine the suitable event loop and coroutine driver for the current environment

    The environment is automatically determined in the order of Factory::$_handlers

  • package_installed used to determine whether the corresponding composer package is installed in the current environment
  • wait_for used for non-blocking waiting of corresponding conditions in the process (usually the result of child coroutine execution)
  • is_coroutine_env used to determine whether the current environment is a workbunny coroutine environment

    After installing workbunny/webman-coroutine, the environment variable WORKBUNNY_COROUTINE=1 will be automatically registered

Documentation

Directory Address
API Fucntion-APIs
Tutorial Introduction to PHP Coroutine
- Installation and Configuration
- Helper Functions
- workerman Environment
- webman Framework
- Explanation of Utils
- Custom Extensions

Participate in Development

Specifications

  • For new feature submissions, please submit a feature issue before submitting a PR to avoid duplicate development;

  • For bug fixes, please submit a bug report issue before submitting a PR to avoid duplicate development;

Tools

  • Code formatting: composer cs-fix
  • Static analysis: composer php-stan
  • Testing and coverage: composer unit-test, the command will generate a report in the coverage directory created in the project
  • function-apis documentation generation:
    • Use composer doc-install or install phpDocumentor yourself
    • Use phpDocumentor to generate documentation in the root directory of the project

♨️ Related Articles

Acknowledgements

Grateful to the workerman and swow development teams for their innovation and excellent contributions to the PHP community. Let's look forward to more breakthroughs in PHP for real-time applications!!!