Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Workerman Bundle Laravel Package

crazy-goat/workerman-bundle

Symfony bundle integrating Workerman to run a high-performance async HTTP server, scheduler and supervisor in pure PHP. Keeps the Symfony kernel/container alive between requests for faster apps. Supports SO_REUSEPORT and optional direct Request creation for speed.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • High-Performance Event-Driven Model: The bundle replaces traditional PHP-FPM + Nginx stacks by leveraging Workerman’s async event loop, preserving Symfony’s DI container between requests. This aligns with modern architectures requiring low-latency, high-throughput APIs (e.g., real-time systems, WebSockets, or high-traffic microservices).
  • Unified Runtime: Consolidates HTTP servers, task scheduling, and process supervision into a single PHP-based runtime, reducing operational complexity (no need for external tools like Supervisord or Cron).
  • Symfony Integration: Seamlessly integrates with Symfony’s ecosystem (e.g., middleware, DI, controllers), enabling gradual adoption without rewriting core logic.
  • PHAR Packaging: Supports self-contained deployments (PHAR), ideal for serverless or containerized environments where dependencies must be bundled.

Integration Feasibility

  • Symfony Compatibility: Works with Symfony 6.4+, leveraging its DI system and console commands. Minimal code changes required for existing apps (e.g., controllers, middleware).
  • Protocol Support: Native support for HTTP/HTTPS, WebSockets, and raw TCP, enabling diverse use cases (e.g., APIs, chat apps, IoT gateways).
  • Middleware Stack: Replaces traditional Symfony HTTP kernels with Workerman’s middleware model, allowing fine-grained request/response manipulation (e.g., auth, rate limiting).
  • Scheduler: Replaces Cron with an in-process task scheduler, reducing latency and eliminating external process management.

Technical Risk

  • Forking Model: Workerman forks processes for workers, which may introduce complexity in:
    • State Management: Shared memory (e.g., Redis) must be used for cross-process state.
    • GRPC/Threads: Requires GRPC_ENABLE_FORK_SUPPORT=1 if using gRPC extensions (risk of deadlocks).
    • Debugging: Async stack traces and process isolation may complicate error diagnosis.
  • Performance Tradeoffs:
    • Memory Usage: Event loop and process supervision add overhead; monitor reload_strategy.memory to avoid leaks.
    • File Monitoring: php-inotify extension recommended for efficient file_monitor reloads (polling mode is CPU-intensive).
  • Security:
    • Privilege Escalation: Binding to ports <1024 requires root or CAP_NET_BIND_SERVICE (mitigate with reverse proxies like Nginx).
    • Trusted Hosts: Misconfiguration of trusted_hosts may expose the app to HTTP host header attacks.
  • Experimental Features:
    • Direct Symfony Request creation (bypassing PSR-7) is experimental; validate stability in production.
    • SO_REUSEPORT requires Linux kernel support (not portable to Windows).

Key Questions

  1. Use Case Alignment:
    • Is the primary goal latency reduction (e.g., real-time APIs) or simplified ops (replacing FPM + Supervisord)?
    • Will the app leverage WebSockets/TCP or remain HTTP-only?
  2. Deployment Constraints:
    • Are root privileges available for port binding (<1024), or will a reverse proxy be used?
    • Is PHAR packaging required (e.g., serverless, Docker), or is a traditional setup acceptable?
  3. State Management:
    • How will shared state (e.g., sessions, caches) be handled across forked workers?
    • Are external services (Redis, databases) stateless or fork-safe?
  4. Observability:
    • Are tools in place to monitor process health, connection metrics, and async stack traces?
    • Will workerman:server connections output suffice for debugging, or are custom metrics needed?
  5. Rollback Strategy:
    • How will the team test rollbacks if the Workerman runtime fails (e.g., fallback to FPM)?
  6. Team Expertise:
    • Does the team have experience with async PHP or event-driven architectures?
    • Is there capacity to debug forking-related issues (e.g., gRPC, shared memory)?

Integration Approach

Stack Fit

  • Symfony Core: Fully compatible with Symfony 6.4+/7.0/8.0; no breaking changes to existing controllers, services, or routing.
  • PHP Extensions:
    • Required: php-event (recommended for performance), php-inotify (for efficient file monitoring).
    • Conditional: grpc (if used, requires GRPC_ENABLE_FORK_SUPPORT=1).
  • Infrastructure:
    • Linux Preferred: SO_REUSEPORT and posix_kill() (for connection introspection) are POSIX-only.
    • Reverse Proxy: Recommended for production (e.g., Nginx) to handle SSL termination, static files, and ports <1024.
  • Alternatives Replaced:
    • PHP-FPM: Replaced by Workerman’s event loop (lower latency, higher concurrency).
    • Nginx/Apache: Static files can be served via StaticFilesMiddleware (though Nginx is still better for high-throughput static assets).
    • Cron/Supervisord: Replaced by Workerman’s built-in scheduler and process supervision.

Migration Path

Phase Action Risk Mitigation
Evaluation Benchmark Workerman vs. FPM for target workload (e.g., RPS, latency). Performance misalignment. Use workerman:server connections to monitor metrics.
Pilot Deploy a non-critical endpoint (e.g., /health) with Workerman. Partial failure. Keep FPM as fallback; use feature flags.
Middleware Refactor Replace Symfony HTTP kernels with Workerman middlewares. Breaking changes in request/response handling. Test with StaticFilesMiddleware first.
Scheduler Migration Move Cron jobs to Workerman’s scheduler (attribute-based or YAML). Job timing discrepancies. Test with PT1M (1-minute) intervals.
Static Files Migrate static assets to StaticFilesMiddleware or keep Nginx. Performance regression. Benchmark both; prefer Nginx for high traffic.
Full Cutover Replace FPM with Workerman for all endpoints. Downtime or errors. Use blue-green deployment.

Compatibility

  • Symfony Features:
    • Controllers: Work unchanged (injected via DI).
    • Routing: Standard Symfony router used; no changes needed.
    • Middleware: Replace KernelInterface middleware with MiddlewareInterface (see execution order).
    • Messenger: Async messages can be processed in workers, but ensure fork safety (e.g., avoid in-memory transports).
  • Third-Party Packages:
    • Doctrine: Works if connections are fork-safe (e.g., PDO with PDO::ATTR_PERSISTENT disabled).
    • Symfony Cache: Use distributed caches (Redis) for cross-process state.
    • API Platform: Test WebSocket/HTTP hybrid endpoints.
  • Legacy Code:
    • Avoid global state (e.g., static variables) due to forking.
    • Replace register_shutdown_function() with Workerman’s event hooks.

Sequencing

  1. Infrastructure Setup:
    • Install required PHP extensions (php-event, php-inotify).
    • Configure reverse proxy (Nginx) for SSL and static files (optional).
  2. Configuration:
    • Add WorkermanBundle to bundles.php.
    • Define minimal workerman.yaml (e.g., listen, processes).
    • Configure reload_strategy (e.g., file_monitor for dev, memory for prod).
  3. Middleware Layer:
    • Implement custom middlewares (e.g., auth, logging).
    • Replace static file serving with StaticFilesMiddleware.
  4. Scheduler:
    • Migrate Cron jobs to Workerman’s scheduler (start with simple intervals).
  5. Testing:
    • Load test with wrk or k6 to compare FPM vs. Workerman.
    • Validate connection metrics (workerman:server connections).
  6. Deployment:
    • Start in daemon mode (-d) and monitor logs (stdout_file).
    • Use workerman:server restart -g for zero-downtime updates.

Operational Impact

Maintenance

  • Configuration:
    • Centralized in workerman.yaml (e.g., ports, processes, reload strategies).
    • Use bin/console config:dump-reference workerman to document options.
  • Logging:
    • Centralized logs in var/log/workerman.log and var/log/workerman.stdout.log.
    • Structured connection metrics via workerman:server connections.
  • Updates:
    • Bundle updates may require testing for compatibility (e.g., PHP 8.3 features).
    • Monitor Workerman’s GitHub for breaking changes
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity