parallel processing?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rkatl
Forum Newbie
Posts: 17
Joined: Tue Apr 22, 2008 8:20 pm

parallel processing?

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: parallel processing?

Post 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?
rkatl
Forum Newbie
Posts: 17
Joined: Tue Apr 22, 2008 8:20 pm

Re: parallel processing?

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: parallel processing?

Post 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.
rkatl
Forum Newbie
Posts: 17
Joined: Tue Apr 22, 2008 8:20 pm

Re: parallel processing?

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: parallel processing?

Post 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.
rkatl
Forum Newbie
Posts: 17
Joined: Tue Apr 22, 2008 8:20 pm

Re: parallel processing?

Post by rkatl »

Thanks for your inputs. Really appreciate it.
rkatl
Forum Newbie
Posts: 17
Joined: Tue Apr 22, 2008 8:20 pm

Re: parallel processing?

Post by rkatl »

Thanks for your inputs. Really appreciate it.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: parallel processing?

Post by pickle »

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.
rkatl
Forum Newbie
Posts: 17
Joined: Tue Apr 22, 2008 8:20 pm

Re: parallel processing?

Post 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
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: parallel processing?

Post by yacahuma »

gearman works. I have been using it for years. I saw something interesting www.rabbitmq.com
Post Reply