How feixuekeji/flysocket works
Project type and purpose
• This is a WebSocket-based MVC framework (“flysocket”) built on top of GatewayWorker/Workerman.
• Its goal is to provide a unified long-connection interface (Web, App, IoT) that stays resident in memory, avoiding repeated FPM bootstraps.
• It follows MVC conventions inspired by ThinkPHP and integrates ThinkORM, Redis caching, logging, validation, and token auth.
File structure
Top-level components and their roles:
· application/… – contains your MVC controllers, models and validators (admin and index modules)
· lib/… – core framework classes (App, Autoloader, Container, Facade, Route, Request, Session, Cache, Log, Validate, Error)
· extend/Token.php – JWT or token-based authentication helper
· config/… – all runtime configuration (database, cache, session, logging, custom cron, common constants)
· route/route.php – WebSocket route definitions or controller bindings
· worker/… – GatewayWorker startup scripts (start_gateway.php, start_businessworker.php, start_register.php, start_http_server.php, plus Events.php)
· socket.js, ws.html – sample front-end WebSocket client implementations
· start.php / start_for_win.bat – bootstrap scripts for launching all worker processes
· Dockerfile – containerization for the entire stack
README for additional insights
• Emphasizes GatewayWorker’s three roles (Gateway, BusinessWorker, Register)
• Mentions long-connection JSON messaging, MVC, ThinkORM integration, facades, validators
Main components and interactions
A. Clients
• Browser/Web (ws.html)
• Node/JS apps (socket.js)
• Mobile/IoT devices
B. GatewayWorker cluster
1. Gateway processes
· Listens on WS/TCP port
· Terminates raw sockets, handles handshake, heartbeat
2. Register service
· Keeps track of active BusinessWorkers and Gateways
· Facilitates service discovery
3. BusinessWorker processes
· Loads the PHP MVC framework (lib/ + application/)
· Runs your controllers (application/*/controller) and models (ThinkORM)
· Uses facades to access Cache, Log, Request, Session, Route
C. HTTP server process (optional: start_http_server.php)
• Exposes HTTP endpoints (maybe for health checks, static assets)
D. Supporting services
• MySQL (config/database.php via ThinkORM)
• Redis (config/cache.php, lib/Redis.php)
• File/system logging (config/log.php, lib/Log.php)
E. Shared configuration and utilities
• Config container (lib/Config.php)
• Dependency injection / service container (lib/Container.php)
• Token auth (extend/Token.php)
Architectural patterns and design principles
• MVC: clear separation of controllers, models, validation
• Facade pattern: static proxies to services (lib/facade/*.php)
• DI/Service Container: resolves dependencies via Container.php
• Process separation: Gateway vs BusinessWorker vs Register vs HTTP
• JSON message format over WebSocket
• ThinkORM integration for database abstraction
• Token-based authentication extension
– Gateway nodes (rectangle “Gateway (Workerman)”)
– Register service (rectangle “Register”)
– BusinessWorker nodes (rectangle “BusinessWorker + flysocket MVC”)
c. External services on the right:
• Clients → Gateway (WebSocket handshake & messages)
• Gateway ↔ Register (service discovery)
• Gateway → BusinessWorker (message dispatch)
• BusinessWorker → MySQL / Redis / Log (via lib classes & config)
• BusinessWorker → Gateway → Clients (responses/events)