tags:

views:

163

answers:

1

I have tried on two different servers to get beanstalkd up and running and do a couple tests (locally on MacOSX compiled from source, and on a CentOS server installed with yum)

I can get the server running either with

sudo beanstalkd -d -p 11300

or

sudo beanstalkd -p 11300 &

I then tried using the php lib and it just froze. Connecting directly:

telnet localhost 11300

I do the following to mimic the PHP test script:

use foo
USING foo
put 0 0 120 5
hello
INSERTED 1
reserve-with-timeout 0
TIMED_OUT

If I just run

reserve

It's stuck indefinitely.

PHP code is

    /**
    * BeanStalk 0.10 - Example code
    * 
    * This is a quick example to get you started using the client.
    */

    require(dirname(__FILE__).'/../src/BeanStalk.class.php');

    /**
    * Connect to the beanstalkd server(s)
    * 
    * Option array:
    * 
    *       array(
    *           'servers'               => array( 'ip:port'[, 'ip:port'[, ...]] ),
    *           'select'                => 'random wait',
    *           'connection_timeout'    => 0.5,
    *           'peek_usleep'           => 2500,
    *           'connection_retries'    => 3,
    *           'auto_unyaml'           => true
    *       );
    * 
    * select -> this tells the client what type of blocking to use when selecting from 
    * different servers. There are currently four choices:
    * 
    *   random wait:        pick a random server from the list and wait for a job
    * 
    *   sequential wait:    pick the next server in the list and wait for a job
    * 
    *   random peek:        in a loop, pick a random server and peek-ready(), looking for a job
    *                       until a server is found that has something available.
    * 
    *   sequential peek:    in a loop, pick the next server and peek-ready() ... etc.
    * 
    * the *peek modes have a companion setting, peek_usleep, which tells the client how long
    * to usleep() for between peeks to servers.
    * 
    * auto_unyaml -> if true, this causes the client to assume the presence of the syck yaml
    * parser, and attempts to 'unyamlize' yaml output for you before returning it.
    */
echo "opening\n";
    $beanstalk = BeanStalk::open(array(
        'servers'       => array( '127.0.0.1:11300' ),
        'select'        => 'random peek'
    ));

echo "switching tube\n";

    // As in the protocol doc.
    $beanstalk->use_tube('foo');

echo "putting job\n";

    // As in the protocol doc.
    $beanstalk->put(0, 0, 120, 'say hello world');      // Add a job to the queue with highest priority, 
                                                        // no delay, 120 seconds TTR, with the contents
                                                        // 'say hello world'.

                                                        // NOTE: the put() method here supports a final optional 
                                                        // argument, a tube name. If supplied, the server will
                                                        // first switch to that tube, write the job, then switch
                                                        // back to the old tube again.

echo "trying to reserve\n";

    // As in the protocol doc.
    $job = $beanstalk->reserve();                       // Assuming there was nothing in the queue before 
                                                        // we started, this will give us our 'hello world'
                                                        // job back.

echo "about to output\n";    

    // This is a BeanQueueJob object.
    echo $job->get();                                   // Output: 'say hello world'

    Beanstalk::delete($job);                            // Delete the job.

and just freezes on "trying to reserve". Original code from:

http://sourceforge.net/projects/beanstalk/

Any ideas? Thanks in advance.

+3  A: 

To use tubes other than default it looks like you need to add a "watch" for that tube. For example:

use foo
USING foo
put 0 0 120 5
hello
INSERTED 1
reserve-with-timeout 5
TIMED_OUT
list-tubes
OK 20
---
- default
- foo

watch foo
WATCHING 2
reserve-with-timeout 5
RESERVED 1 5
hello

This isn't too clear on the documentation, which seems to imply that the "use" command automatically has reserve commands using the tube - just as put automatically uses that tube.

Hope this helps other beanstalkd newbies!

Brian Hogg
You might want to have a look at the [beanstalkc tutorial](http://github.com/earl/beanstalkc/blob/master/TUTORIAL) (esp. [line 138ff](http://github.com/earl/beanstalkc/blob/master/TUTORIAL#L138)). Even though the tutorial was written for a Python client library, it covers most beanstalkd aspects and could be useful for users of other languages/libraries as well.
earl
Brilliant, thanks for the link earl - easy to translate that into other languages/libraries as an intro.
Brian Hogg
using keyword is for putting data in the tube, watch keyword is to retrieve one. the answer is good, the problem that the problem author write to a tube he does not watched
asdmin