1

I have just started using pheanstalk and am having an issue with the reserve function. I have the following code for a worker script:

<?php
  //... code that requires the autoload.php page among and other

  $queue = new Pheanstalk_Pheanstalk("127.0.0.1:11300");
  $queue->watch("action_tube");
  $job = $queue->reserve();

  //... code that would then output the information obtained from the job
?>

The issue I am having is that the code always gets stuck when preforming the reserve function. I know for a fact that it is getting stuck there because I went through the effort of running this code in a browser and using echo while commenting out code to see exactly where the code is getting stuck. It's as if an infinit while loop is happening inside the reserve function.

For instance, if I were to comment out $job = $queue->reserve(), the code would low freely and the page would immediately load, however if I don't comment it out, the circle loading in the browser keeps on going forever.

QUESTION: Why might I be having this problem? Is this normal for the reserve function? Does it just stand waiting for something to appear in the queue? I do actually have the "action_tube" queue created from a previous script so I would think that the reserve function would take some of these out. Might the condition of the queue cause a reserve function to stall? Any feedback is greatly appreciated!

Alister Bulman
  • 34,482
  • 9
  • 71
  • 110
Webeng
  • 7,050
  • 4
  • 31
  • 59

1 Answers1

4

Beanstalk reserve will run forever until the job is ready

reserve blocks until a job is ready, possibly forever. If that is not desired, we can invoke reserve with a timeout (in seconds) how long we want to wait to receive a job. If such a reserve times out, it will return None:

>>> beanstalk.reserve(timeout=0) is None
True

Found this here

Barmar
  • 741,623
  • 53
  • 500
  • 612
vijaykumar
  • 4,658
  • 6
  • 37
  • 54