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

Pheanstalk Bundle Laravel Package

anglemx/pheanstalk-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require anglemx/pheanstalk-bundle
    

    Add to config/bundles.php:

    Angle\PheanstalkBundle\PheanstalkBundle::class => ['all' => true],
    
  2. Configure (config/packages/angle_pheanstalk.yaml):

    angle_pheanstalk:
        connections:
            default:
                host: '127.0.0.1'
                port: 11300
                timeout: 10
    
  3. First Use Case: Inject PheanstalkInterface into a service/controller:

    use Angle\PheanstalkBundle\Client\PheanstalkInterface;
    
    public function __construct(private PheanstalkInterface $pheanstalk) {}
    
    // Producer
    $this->pheanstalk->useTube('jobs')->put('Process user:123');
    
    // Worker (CLI)
    $job = $this->pheanstalk->watch('jobs')->reserve();
    $job->delete();
    

Implementation Patterns

Core Workflows

  1. Job Production:

    $this->pheanstalk
        ->useTube('high_priority')
        ->put('data', 0, 3600, 1024, 'unique-job-id'); // priority, delay, ttr, size
    
  2. Job Consumption (Worker):

    $job = $this->pheanstalk
        ->watch('high_priority')
        ->ignore('low_priority')
        ->reserve(10); // timeout
    
    if ($job) {
        $data = $job->getData();
        $job->delete(); // or release() if retry
    }
    
  3. Batched Processing:

    for ($i = 0; $i < 10; $i++) {
        $job = $this->pheanstalk->reserve();
        if (!$job) break;
        // Process job...
    }
    

Integration Tips

  • Symfony Events: Dispatch PheanstalkEvents (e.g., JobReservedEvent) for cross-cutting logic.
  • Profiler: Enable via angle_pheanstalk.profiler: true to monitor queue metrics.
  • CLI Commands: Use angle:pheanstalk:list-tubes or angle:pheanstalk:peek-job for debugging.

Auto-Wiring

// services.yaml
services:
    App\Service\JobProcessor:
        arguments:
            $pheanstalk: '@angle.pheanstalk'

Gotchas and Tips

Pitfalls

  1. Connection Timeouts:

    • Default timeout (10s) may be too short for slow workers. Increase via config.
    • Use ->connect() explicitly if reusing connections across requests.
  2. Job Stuck in "Ready" State:

    • Check ttr (time-to-run) isn’t too short. Default is 1 second in Pheanstalk.
    • Use ->release($job, 60) to retry with a longer delay.
  3. Symfony Event Order:

    • Events fire after job operations (e.g., JobReservedEvent triggers post-reserve).
    • Avoid modifying job state in event listeners.

Debugging

  • CLI Commands:
    php bin/console angle:pheanstalk:stats  # Server stats
    php bin/console angle:pheanstalk:list-tubes  # Tube contents
    
  • Profiler: Check the "Beanstalkd" tab in Symfony’s Dev Toolbar for queue metrics.

Extension Points

  1. Custom Proxy: Override Angle\PheanstalkBundle\Client\Proxy\PheanstalkProxy to:

    • Add retry logic.
    • Log all operations.
    angle_pheanstalk:
        proxy_class: App\Proxy\CustomPheanstalkProxy
    
  2. Event Subscribers:

    use Angle\PheanstalkBundle\Event\JobReservedEvent;
    
    public static function getSubscribedEvents(): array
    {
        return [
            JobReservedEvent::class => 'onJobReserved',
        ];
    }
    
  3. Connection Management:

    • For high-throughput apps, manage connections manually:
      $connection = $this->pheanstalk->getConnection();
      $connection->useTube('custom')->put(...);
      

Config Quirks

  • Multiple Connections:

    angle_pheanstalk:
        connections:
            primary: { host: '127.0.0.1', port: 11300 }
            backup:  { host: '10.0.0.1', port: 11300 }
    

    Inject via angle.pheanstalk.primary or angle.pheanstalk.backup.

  • Environment-Specific: Use %env(BEANSTALK_HOST)% in config for dynamic values.

Performance

  • Bulk Operations: Use ->peek() + ->delete() loops instead of ->reserve() in tight loops.
  • Tube Binding: Pre-bind tubes in workers to avoid repeated ->watch() calls.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
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
christhompsontldr/laravel-inky