Search by

bearlord / yew-framework

bearlord

A swoole distributed framework for network application

Package info

github.com/bearlord/yew-framework

pkg:composer/bearlord/yew-framework

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

2.1 2026-09-21 13:09 UTC

This package is auto-updated.

Last update: 2026-09-30 08:07:49 UTC


README

A high-performance, Swoole-powered, plugin-oriented PHP application framework for building long-running, concurrent, multi-process services (MQTT brokers, WebSocket gateways, RPC servers, game/IM backends, etc.).

中文文档 | English Docs

Why Yew

  • Built on Swoole coroutines — millions of concurrent connections, native async I/O, no blocking.
  • True multi-process model — Master / Manager / Worker / custom helper processes, each isolated, coordinated through shared memory tables and a typed IPC layer.
  • Plugin-first architecture — every capability (Actor, Cluster, MQTT, Database, Redis, Queue, AOP, Route, Security …) is a plugin with a well-defined lifecycle and dependency ordering.
  • Actor model — Akka-style actors with mailboxes, supervision, typed messages, routing (round-robin / consistent-hash / least-loaded) and optional event-sourcing.
  • Clustering out of the box — Gossip membership, consistent-hash shard routing, location-transparent cross-node Actor transport, cluster-wide broadcast, and Actor replica / failover.
  • MQTT server support — first-class MQTT 3.1.1/5.0 packet handling, subscription trees with +/# wildcards, connection state in a dedicated helper process, and optional cross-node delivery.
  • Rich data layer — PDO connection pools, Redis pools (standalone/cluster/sentinel), Yii-style ActiveRecord, Redis-backed queue, and AMQP (RabbitMQ) producers/consumers.
  • AOP & cross-cutting — source-transforming AOP (auth, rate-limit, circuit-breaker, routing, logging) plus scheduling, validation, session, JWT, and Snowflake ID generation.

Requirements

Requirement Version
PHP >= 8.2
Swoole >= 5.1 (recommended >= 6.2; coroutine, async, table, process enabled)
Extensions pdo, redis, bcmath (AMQP), inotify (optional, for hot reload)
Composer >= 2.0

Quick Start

1. Install

composer require bearlord/yew-framework

2. Bootstrap (server.php)

<?php
require __DIR__ . '/vendor/autoload.php';

use Yew\Framework\Application;

$app = new Application();
$app->addPlugin(new \Yew\Plugins\Database\DatabasePlugin());
$app->addPlugin(new \Yew\Plugins\Redis\RedisPlugin());
$app->addPlugin(new \Yew\Plugins\Route\RoutePlugin());
$app->addPlugin(new \Yew\Plugins\Mqtt\MqttPlugin());
$app->addPlugin(new \Yew\Plugins\Mqtt\Connection\MqttConnectionPlugin());
$app->run(App\Application::class);

3. Configuration (resources/application.yml + profile)

yew:
  server:
    name: yew-app
    worker_num: 4
  port:
    http:
      protocolType: http
      host: 0.0.0.0
      port: 8080
    mqtt:
      protocolType: mqtt
      host: 0.0.0.0
      port: 1883
      packTool: 'Yew\Plugins\Mqtt\MqttPack'
  logger:
    level: debug
  db:
    default:
      dsn: 'mysql:host=127.0.0.1;dbname=test'
      username: root
      password: root
  redis:
    default:
      host: 127.0.0.1
      port: 6379

Config is loaded from resources/application.yml then overlaid by resources/application-{profile}.yml (profile selected by yew.profiles.active). See Getting Started for the full mechanism.

4. Run

php server.php          # start (debug mode)
php server.php start -d # daemonize

Architecture at a Glance

                 ┌───────────────────────────────────────────────┐
                 │                  Swoole Server                 │
   clients ─────▶├─ Master ─ Manager ─ Worker(s) ─ Helper(s)      │
                 │                     │            │             │
                 │            IPC ─────┴────────────┘             │
                 │            (typed, process-to-process)         │
                 └───────────────────────────────────────────────┘
                          ▲                      ▲
                    Cluster gossip       Cluster broadcast (UDP)
                          ▲                      ▲
                    Other Yew nodes  ◀────────────┘
  • Worker processes run your controllers, actors, and business logic.
  • Helper processes host shared state (cluster-state, mqtt-connection, topic, multicast, queue …).
  • IPC lets any process call typed methods on another process without blocking the event loop.
  • Cluster (optional) links multiple nodes via Gossip + a dedicated UDP/TCP transport.

Documentation

Section English 中文
Getting Started en-US zh-CN
Actor model en-US zh-CN
Multicast (pub/sub) en-US zh-CN
AOP en-US zh-CN
Cluster en-US zh-CN
MQTT en-US zh-CN
Route en-US zh-CN
Pack en-US zh-CN
RPC & HTTP Client en-US zh-CN
Database en-US zh-CN
Redis en-US zh-CN
Queue en-US zh-CN
AMQP en-US zh-CN
Scheduled en-US zh-CN
Security & Session & Validate & JWT en-US zh-CN
Rate Limit & Circuit Breaker en-US zh-CN
Utilities (Uid, Topic, Connection, Console, AutoReload…) en-US zh-CN

License

MIT © bearlord