Using Nette in a PHP daemon

Notice: This thread is very old.
siq
Member | 2
+
0
-

Hi,
I need to write a series of PHP daemons for one of my projects written in Nette. I can't use Cron because the daemons need to be able to react to a message immediately. I want to use PHP and Nette because I want to be able to reuse existing code from the models. Also let's ignore the problem with possible memory leaks, and/or GC issues.
So far I had two ideas, the first one is to copy the micro blog example and somehow hack it to do what I want, or use the CLI router somehow.
Frankly, I don't like either of those ideas, the first one sounds quite nasty. for the second one, I'd have to put the daemon logic into a presenter, and I don't like that idea.
How would you go about it? Is there a smart way to achieve this?
Thanks in advance.

bazo
Member | 620
+
0
-

why would you want to commit such atrocities?

i use the following approach

file daemon.php

<?php

$container = require_once __DIR__ . '/../bootstrap.php';

$daemon = $container->ironMQConsumer;
$queue = 'queueName';
$callback = callback($container->messageProcessor, 'process');
$daemon->bindQueue($queue)->addCallback($callback)->consume();
?>

where consume() function contains some while or whatever that reads messages from queue

bazo
Member | 620
+
0
-

or use symfony console and write it as a command, which executes something in a loop. or you can react. there's a ton options, all boil down to a while cycle

siq
Member | 2
+
0
-

bazo wrote:

why would you want to commit such atrocities?

Because I'm a Java dev and I only do Nette for fun on my side projects, therefore I'm not very good at it.
Anyway, thanks a lot for the reply, it was very helpful.

Aurielle
Member | 1281
+
0
-

I'm running project of a similar approach with ReactPHP, works just fine, except for my laziness to write some parts like autoreconnecting.