How fangfengxiang/beacon works
php-beacon-extension is a PHP-FPM C extension for pool health, governance-worker scheduling, and shared-memory service discovery. Its main flow is: FPM workers publish pool activity and use Beacon APIs; a separate governance process invokes PHP-provided registry callbacks, calculates health, and refreshes the shared node cache for workers. The README also documents built-in FileRegistry operation, load balancing, failover, and Yar integration. Some internal calls and the implementation of the unsampled governance script are not shown, so those links rely on README statements rather than inferred source relationships.
Main entry points: beacon_shm.c 双缓冲共享内存 · beacon.c Module hooks · beacon_api_governance.c Governance API · governance.php Governance loop
Components 17
Extension lifecycle
- FPM master
- Module hooks
beacon.c - Worker lifecycle
beacon_governance_worker.c - Runtime configuration
beacon_config.c - Logging
beacon_log.c
Request APIs
- FPM workers
- Beacon API
beacon_api.c - Node selection
beacon_service_select.c - Pool health
beacon_service_health.c
Governance runtime
- Governance API
beacon_api_governance.c - Callback SPI
beacon_callback.c - Governance loop
governance.php - FileRegistry
governance.php
Shared state
- 双缓冲共享内存
beacon_shm.c - 共享数据 layout
beacon_shm.h
Other components
- PHP application
- Registry service
Connections 19
- PHP application → Beacon API: calls
README.md - Beacon API → Node selection: selects nodes
README.md - Node selection → 双缓冲共享内存: reads node cache
README.md - PHP application → Beacon API: reports health
README.md - FPM workers → 双缓冲共享内存: updates counters
README.md - FPM master → Module hooks: runs lifecycle hooks
beacon.c - Module hooks → 双缓冲共享内存: initializes shared state
README.md - Module hooks → Worker lifecycle: spawns worker
beacon.c - Worker lifecycle → Governance loop: executes script
beacon_governance_worker.c - Governance loop → Callback SPI: invokes callbacks
README.md - Callback SPI → Registry service: calls injected logic
README.md - Governance loop → Governance API: uses API
README.md - Governance API → 双缓冲共享内存: writes node cache
beacon_api_governance.c - Governance API → Pool health: calculates health
README.md - Pool health → 双缓冲共享内存: reads counters
beacon_service_health.c - FileRegistry → Registry service: provides local registry
README.md - Runtime configuration → Module hooks: configures runtime
- Module hooks → Logging: logs lifecycle
beacon.c - 共享数据 layout → 双缓冲共享内存: defines layout
beacon_shm.h