su debian/ubuntu si installa da apt e si fa partire al solito modo

sudo /etc/init.d/beanstalkd start
  • usa "Process supervision" per assicurarti che i "workers" siano attivi: Monit
  • in alternativa supervisord o daemontools
  • http://www.contentwithstyle.co.uk/content/php-worker-processes-with-beanstalk-and-daemontools/
  • http://workingwithunixprocesses.com
  • https://github.com/dustin/beanstalk-tools
<?php
require_once('pheanstalk/pheanstalk_init.php');
$pheanstalk = new Pheanstalk('127.0.0.1:11300');

for(
$i=0$i<1000$i++) {
  
$job = new stdClass();
  
$job->envelope_id rand();
  
$job->date date('Y-m-d H:i:s');
  
$job_data json_encode($job);
  
$pheanstalk->useTube('test')->put($job_data);
  echo 
"pushed: " $job_data "\n";
}
<?php
class Worker {

  private 
$path;

  public function 
__construct($path) {
    
$this->setBasePath($path);
    
$this->log('starting');
    require_once(
'pheanstalk/pheanstalk_init.php');
    
$this->pheanstalk = new Pheanstalk('127.0.0.1:11300');
  }

  public function 
__destruct() {
    
$this->log('ending');
  }

  private function 
setBasePath($path) {
    
$this->path $path;
  }

  public function 
run() {
    
$this->log('starting to run');
    
$cnt 0;
    
$done_jobs = array();

    while(
1) {
      
$job $this->pheanstalk->watch('test')->ignore('default')->reserve();
      
$job_encoded json_decode($job->getData(), false);
      
$done_jobs[] = $job_encoded;
      
$this->log('job:'.print_r($job_encoded1));
      
$this->pheanstalk->delete($job);
      
$cnt++;

      
$memory memory_get_usage();

      
$this->log('memory:' $memory);

      if(
$memory 1000000) {
        
$this->log('exiting run due to memory limit');
        exit;
      }

      
usleep(10);
    }
  }

  private function 
log($txt) {
    
file_put_contents($this->path '/log/worker.txt'$txt "\n"FILE_APPEND);
  }
}

$worker = new Worker(dirname($argv[0]));
$worker->run();

supervisord

sudo apt-get install supervisor
sudo vi /etc/supervisor/conf.d/beanstalk.conf
 
sudo /etc/init.d/supervisor stop
sudo /etc/init.d/supervisor start
 
# script di controllo
supervisorctl

impostare un job di monitoring

[program:my_worker]
command=/var/beanstalk-listeners/java-worker/run_worker.sh production
autostart=true
autorestart=true
stdout_logfile=/var/beanstalk-listeners/java-worker/worker-out.log
;stdout_logfile_maxbytes=1MB
;stdout_logfile_backups=10
;stdout_capture_maxbytes=1MB
stderr_logfile=/var/beanstalk-listeners/java-worker/worker-err.log
;stderr_logfile_maxbytes=1MB
;stderr_logfile_backups=10
;stderr_capture_maxbytes=1MB