Page 1 of 1
parallel processing?
Posted: Fri Oct 12, 2012 3:16 pm
by rkatl
Can someone suggest a best approach to kick-off multiple processesin php?
For example, I've script that currently calls the webservices one after the other in a for-loop.
However, we need a way to call all those web services at the same time and gather the response from each of those.
Appreciate any pointers.
Re: parallel processing?
Posted: Fri Oct 12, 2012 7:39 pm
by requinix
PHP is not built for multiple processes/threads or asynchronicity. If you want to make a command-line script it's a bit easier but you still have to tie everything together at the end, deal with interrupts, handle concurrency, and the other headaches associated with multithreading.
Is there a problem with doing them in series?
Re: parallel processing?
Posted: Sun Oct 14, 2012 9:14 am
by rkatl
It is not the problem running in series. It is the requirement to somehow run in parallel. Each web service request takes around 5 secs and we wanted to run couple of services at the same time.
here are a couple of links I found by googling. Wondering if any of these works.
http://blog.motane.lu/2009/01/02/multithreading-in-php/
http://phplens.com/phpeverywhere/?q=node/view/254
Re: parallel processing?
Posted: Sun Oct 14, 2012 5:00 pm
by requinix
The first one is pretty decent but could be better by listening for a SIGCHLD (system will tell you when a child thread exits) and/or doing a waitpid without W_NOHANG (allow the parent thread to wait indefinitely until a child exits).
The second one is inappropriate, and its comment about packet lengths is very much incorrect.
Re: parallel processing?
Posted: Sun Oct 14, 2012 5:34 pm
by rkatl
Thank you!
Do you have any thoughts on the Gearman. Wondering if this is only good for spanning multiple process (without a way to get a response from each process in the same thread)
http://www.php.net/manual/en/intro.gearman.php
Re: parallel processing?
Posted: Sun Oct 14, 2012 6:25 pm
by requinix
Never used Gearman before.
The third example seems to demonstrate a way to run functions asynchronously and still receive data from them, so I think Gearman can work for you. But you'd have to install it and run the server. If that's an option then consider it; even though it's a bit of work for a single use case (as I understand your problem), writing something from scratch may simply not be an option for you.
Re: parallel processing?
Posted: Mon Oct 15, 2012 6:54 am
by rkatl
Thanks for your inputs. Really appreciate it.
Re: parallel processing?
Posted: Mon Oct 15, 2012 6:54 am
by rkatl
Thanks for your inputs. Really appreciate it.
Re: parallel processing?
Posted: Mon Oct 15, 2012 2:18 pm
by pickle
Are you accessing these services through cron, or by opening a web page?
Re: parallel processing?
Posted: Thu Oct 18, 2012 1:46 pm
by rkatl
it is through zend framework, Basically, web page calls a zend controller and the controller need to call multiple webservices at the same time
Re: parallel processing?
Posted: Fri Oct 26, 2012 8:11 pm
by yacahuma
gearman works. I have been using it for years. I saw something interesting
www.rabbitmq.com