parallel processing?
Moderator: General Moderators
parallel processing?
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.
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?
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?
Is there a problem with doing them in series?
Re: parallel processing?
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
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?
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.
The second one is inappropriate, and its comment about packet lengths is very much incorrect.
Re: parallel processing?
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
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?
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?
Thanks for your inputs. Really appreciate it.
Re: parallel processing?
Thanks for your inputs. Really appreciate it.
Re: parallel processing?
Are you accessing these services through cron, or by opening a web page?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: parallel processing?
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?
gearman works. I have been using it for years. I saw something interesting www.rabbitmq.com