Zend_daemon with Zend_Queue

12 views
Skip to first unread message

Denis Baklikov

unread,
Aug 21, 2009, 1:32:03 AM8/21/09
to concentr...@googlegroups.com
Hi, Sébastien/Daniel

Yesterday evening I have created a prototype of Zend_Daemon with Zend_Queue 
and also found a bug in the Zend_Queue_Adapter_Array :)

In this sample Queue fill in the beginning and processes later, but in real application we should do it from different files 

Please let me know if you have any questions.

Here is sample code:

$queue = new Zend_Queue('Array');
// Create a new queue
$queue2 = $queue->createQueue('queue');

//fill the queue
for ($i=0; $i=100; $i++) {
$queue->send('My Test Message '.$i);
}

// I will implement this function later
function countAvailableInPool() {
  return 5;
}

while (!$stop) {
// count available reources in pool
$cnt = countAvailableInPool();
// read from queue and process them
$messages = $queue->receive($cnt);
foreach ($messages as $i => $message) {
   echo "$i) Message => ", $message->body, "\n";
}
// wait for processes finish
sleep(1);



--
Kind regards,
 Denis Baklikov

scramatte

unread,
Aug 21, 2009, 2:32:51 PM8/21/09
to concentre-daemon

As I tell you I'm newbie with Queue, so I've start searching google
and I've found some articles about Zend_Queue

http://the.0gravity.co.uk/universe/php/zend/queue/
http://www.zfsnippets.com/snippets/view/id/60/zendqueue-simple-example-for-offline-processing

Nothing very clear :( ... and I've got some questions :

If we use a Db adapter or Memcache it will be possible to add job to
the queue from another place (eg: the main webpage) ?
If we use array we will loose Queue context accros various page or
daemon ?
In our case message are the process ... isn't it, might be we can
extends ZendX_Console_Unix_Process class ?

The loop will be :

while ( $cnt = countAvailableInPool()) {

...

}

isn't it ?

Denis Baklikov

unread,
Aug 23, 2009, 1:25:19 AM8/23/09
to concentr...@googlegroups.com
Hello,

Sorry for delay, I was on holiday...
Here are answers to your questions:

If we use a  Db adapter or Memcache it will be possible to add job to
the queue from another place (eg: the main webpage)  ?

Yes, it is the main feature of the application which are using queues. Jobs to queue add from the different place (e.g job scheduler) and processes from the other place.


If we use array we will loose Queue context accros various page or
daemon ?

I used Array_Adapter only for demonstration Zend_Queue's functions.
In the documentation developers of Zend_Queue suggested to use Array_Adapter only for testing. For the production use, I recommend DB adapter or Apache ActiveMQ

In our case  message are the process ...
Not exactly... Message is a definition of the process. Daemon will launch ZendX_Console_Unix_Process using parameters from the "message".
 
 
Regards,

Denis
Reply all
Reply to author
Forward
0 new messages