by Kevin Schroeder | 8:24 am

I love most things about PHP, but what I don’t like is that in order for me to do any kind of asynchronous processing I need to create an infrastructure.  In other words, I need to build a queuing daemon or build some kind of interface.

It really shouldn’t be that much work for what is a simple task in many other languages.

So it would be really cool if PHP-FPM had a FIFO/delayed queue where you could inject a FastCGI request into the queue and do either fire and forget or allow the executing process to wait on a queue selector.  So it would look kind of like this

1
2
3
4
5
$j1 = new FpmRequest('/some/url', 'POST', array('var' => 1, 'var2' => 2));
 
$q = new FpmQueue();
$q->addJob($j1);
$q->execute();

or if you want to wait for the response, this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$j1 = new FpmRequest('/some/url', 'POST', array('var' => 1, 'var2' => 2));
$j2 = new FpmRequest('/some2/url2', 'POST', array('var' => 1, 'var2' => 2));
$j3 = new FpmRequest('/some3/url3', 'POST', array('var' => 1, 'var2' => 2));
$q = new FpmQueue();
$q->addJob($j1);
$q->addJob($j2);
$q->addJob($j3);
 
$q->execute();
$q->wait();
 
echo $j1->getOutput();
echo $j2->getOutput();
echo $j2->getOutput();

It would be nice for the Apache SAPI to do this as well, so I could debug the requests easier (I use Zend Server which, ATM, only supports Apache).  But it would seem that PHP-FPM would have an easier time of doing this because it manages its own resources it could do things like maintain a separate pool reserved for queued requests.

Maybe I have unique use cases or I just like making things more complicated for myself.  But it would be really nice to have some kind of queuing work out of the box.

PHP
Tags: ,

Comments

bentleyy

It really shouldn’t be that much work for what is a simple task in many other languages.

Jul 24.2014 | 08:46 am

bentleyy

thanks so much

Jul 24.2014 | 08:48 am

kenedyy

It really shouldn’t be that much work for what is a simple task in many other languages.

Jul 24.2014 | 08:52 am

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.