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

Gearman Laravel Package

enqueue/gearman

Gearman transport for Enqueue: send and consume queue messages via a Gearman broker using Enqueue’s queue specification. Part of the php-enqueue ecosystem with docs, support chat, and CI-tested releases.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Decentralized Job Processing: Aligns with Laravel’s need for async job handling but leverages Gearman’s distributed RPC model (vs. traditional message queues). Ideal for legacy systems or custom workflows where Gearman is already embedded.
  • Enqueue Abstraction: Provides a PSR-15-compliant interface, enabling Laravel to interact with Gearman via Enqueue’s standardized Connection and Context objects. Reduces coupling to Gearman’s native API.
  • Protocol Limitations: Gearman lacks native queue features (e.g., priority, delayed jobs, retries), requiring workarounds (e.g., custom job metadata). Best suited for fire-and-forget or simple RPC-style tasks.
  • Laravel Integration: Requires Enqueue’s Laravel bridge (enqueue/laravel), which may introduce indirection but ensures consistency with other Enqueue transports (e.g., Redis, RabbitMQ).

Integration Feasibility

  • Laravel Queue Driver: Can be registered as a custom queue connection in config/queue.php:
    'gearman' => [
        'driver' => 'enqueue',
        'transport' => 'gearman',
        'host' => env('GEARMAN_HOST', 'localhost'),
        'port' => env('GEARMAN_PORT', 4730),
        'timeout' => 5.0,
    ],
    
  • Job Dispatch: Laravel jobs are dispatched via Enqueue’s Producer:
    $producer = app(\Enqueue\Client\Producer::class);
    $producer->send(new ProcessVideoJob(), new \Enqueue\Client\Message());
    
  • Worker Setup: Requires external Gearman workers (not Laravel’s built-in queue workers). Workers must be manually configured to handle job payloads (e.g., via CLI scripts or Docker containers).
  • Dependency Chain: Laravel → enqueue/laravelenqueue/gearman → Gearman Server. Risk: Breaks if any link fails (e.g., Gearman server down, Enqueue version mismatch).

Technical Risk

Risk Impact Mitigation
Deprecated Package No updates since 2017; potential security/compatibility issues. Fork the repo or switch to enqueue/redis for active maintenance.
Gearman Ecosystem Obsolescence Gearman is less performant than modern alternatives (e.g., Redis). Benchmark against enqueue/redis; justify Gearman’s use case (e.g., legacy).
Laravel Plugin Gaps Missing native support for Laravel-specific features (e.g., Queue::later()). Implement custom logic or use Enqueue’s delay extension.
Error Handling Limited visibility into worker failures (e.g., crashed Gearman processes). Integrate with Laravel’s FailedJob events or use a monitoring sidecar.
Scaling Complexity Gearman’s worker affinity may require manual load balancing. Use multiple Gearman servers with consistent hashing or a proxy (e.g., HAProxy).

Key Questions

  1. Strategic Fit:
    • Is Gearman a hard requirement (e.g., existing infrastructure), or is this a technical debt decision?
    • Would a modern alternative (e.g., RabbitMQ, Redis) better align with long-term goals?
  2. Maintenance:
    • Who will monitor and update the Gearman server and workers?
    • Is the team prepared to fork and maintain enqueue/gearman if issues arise?
  3. Performance:
    • What are the expected job volumes? Gearman may bottleneck at scale.
    • How will latency compare to alternatives (e.g., Redis’s in-memory speed)?
  4. Failure Modes:
    • What’s the fallback if Gearman fails (e.g., database queue as backup)?
    • How will job retries be handled (e.g., dead-letter queues)?
  5. Observability:
    • How will job status (e.g., in-progress, failed) be tracked?
    • Are there metrics for Gearman worker health (e.g., CPU, memory)?

Integration Approach

Stack Fit

  • Laravel Compatibility:
    • Pros: Leverages Enqueue’s abstraction layer to unify Gearman with Laravel’s queue system. Supports job batching, serialization, and connection failover.
    • Cons: Requires Enqueue’s Laravel bridge, adding complexity. Not a first-class citizen in Laravel’s ecosystem.
  • Gearman Dependency:
    • Hard Requirement: Gearman server (gearmand) and workers must be externally managed (not part of Laravel’s queue system).
    • Worker Orchestration: Workers can be deployed via:
      • Docker: Containerized Gearman workers with custom PHP scripts.
      • Kubernetes: StatefulSet for high availability.
      • CLI: Direct gearman-worker processes on servers.
  • Alternatives:
    • Redis/RabbitMQ: Better for scalability and modern tooling (e.g., Laravel Horizon).
    • Database Queues: Simpler but less performant for high-throughput workloads.

Migration Path

  1. Phase 1: Proof of Concept
    • Set up a non-production Gearman instance.
    • Integrate enqueue/gearman with a subset of Laravel jobs.
    • Validate:
      • Job dispatching (dispatch(new Job)->onConnection('gearman')).
      • Worker consumption (custom script or gearman-worker).
      • Error handling (failed jobs, timeouts).
  2. Phase 2: Pilot Deployment
    • Migrate low-risk jobs (e.g., batch processing) to Gearman.
    • Monitor:
      • Latency (job processing time).
      • Worker stability (crashes, restarts).
      • Resource usage (CPU, memory).
  3. Phase 3: Full Rollout
    • Update config/queue.php to default to Gearman for target jobs.
    • Deploy production Gearman workers with monitoring (e.g., Prometheus).
    • Train team on Gearman-specific debugging (e.g., gearman --statistics).
  4. Phase 4: Optimization
    • Tune Gearman settings (e.g., gearman --max-threads).
    • Implement circuit breakers for Gearman failures (fallback to database queue).

Compatibility

Component Compatibility Notes Workarounds
Laravel Jobs Must implement ShouldQueue and be serializable (JSON/PHP). Use enqueue/serializer for custom serialization.
Delayed Jobs Not natively supported; requires Enqueue extensions or custom logic. Use Queue::later() with a database fallback or cron-triggered retries.
Retry Logic Limited; relies on Enqueue’s retry configuration. Implement exponential backoff in job code or use a dead-letter queue.
Gearman Workers Must handle job payloads (e.g., gearman --task-background). Write PHP worker scripts or use enqueue/consumer.
PHP Extensions Requires pecl/gearman (may need compilation on some systems). Use Docker images with pre-installed Gearman (e.g., php:8.1-cli + Gearman).

Sequencing

  1. Infrastructure Setup:
    • Deploy Gearman server (gearmand) on a dedicated host or container.
    • Configure workers (e.g., gearman-worker --job-background --task-background).
  2. Package Installation:
    composer require enqueue/gearman enqueue/laravel enqueue/serializer
    
  3. Laravel Configuration:
    • Publish Enqueue’s config:
      php artisan vendor:publish --tag=enqueue-config
      
    • Update config/queue.php:
      'gearman' => [
          'driver' => 'enqueue',
          'transport' => 'gearman',
          'host' => env('GEARMAN_HOST'),
          'port' => env('GEARMAN_PORT', 4730),
          'timeout' => 10.0,
      ],
      
  4. Worker Implementation:
    • Create a worker script (e.g., gearman-worker.php):
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
codifyo/ts-generator-bundle
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
christhompsontldr/laravel-inky
spatie/mailcoach-vapor