title: How to set up Beanstalkd with PHP
body: <p>Recently I've been researching the use of Beanstalkd with PHP. I've learned quite a bit but have a few questions about the setup on a server, etc.</p>
  
  <p>Here is how I see it working:</p>
  
  <ol>
  <li>I install Beanstalkd and any dependencies (such as libevent) on my Ubuntu server. I then start the Beanstalkd daemon (which should basically run at all times).</li>
  <li>Somewhere in my website (such as when a user performs some actions, etc) tasks get added to various tubes within the Beanstalkd queue.</li>
  <li><p>I have a bash script (such as the following one) that is run as a deamon that basically executes a PHP script.</p>
  
  <pre><code>#!/bin/sh
  php worker.php
  </code></pre></li>
  </ol>
  
  <p>4) The worker script would have something like this to execute the queued up tasks:</p>
  
  <pre><code>while(1) {
    $job = $this-&gt;pheanstalk-&gt;watch('test')-&gt;ignore('default')-&gt;reserve();
    $job_encoded = json_decode($job-&gt;getData(), false);
    $done_jobs[] = $job_encoded;
    $this-&gt;log('job:'.print_r($job_encoded, 1));
    $this-&gt;pheanstalk-&gt;delete($job);
  }
  </code></pre>
  
  <p>Now here are my questions based on the above setup (which correct me if I'm wrong about that):</p>
  
  <ol>
  <li><p>Say I have the task of importing an RSS feed into a database or something. If 10 users do this at once, they'll all be queued up in the "test" tube. However, they'd then only be executed one at a time. Would it be better to have 10 different tubes all executing at the same time?</p></li>
  <li><p>If I do need more tubes, does that then also mean that i'd need 10 worker scripts? One for each tube all running concurrently with basically the same code except for the string literal in the watch() function.</p></li>
  <li><p>If I run that script as a daemon, how does that work? Will it constantly be executing the worker.php script? That script loops until the queue is empty theoretically, so shouldn't it only be kicked off once? How does the daemon decide how often to execute worker.php? Is that just a setting?</p></li>
  </ol>
  
  <p>Thanks!</p>