1

Possible Duplicate:
Threads in PHP.

I m getting a list of 20 urls. I need to process some operation on these request simultaneously.

and my php execution will continue only after all request is over.

example

<?php

for($i=0;$i<120;$i++)
{
  //parallel processing of 20 urls
}

come here only if all request are fullfilled
Community
  • 1
  • 1
user746709
  • 33
  • 1
  • 7
  • Why does it need to be simultaneous? What's wrong with doing it sequentially? Are you doing some kind of HTTP request that takes time to execute? – Eric Jun 13 '11 at 12:25

3 Answers3

2

See the curl_multi_ functions

symcbean
  • 47,736
  • 6
  • 59
  • 94
2

There is no inherent multi threading in php.

Instead what you could do is invoke 20 php-cli calls which don't return anything to the caller. :)
(Thats bullish, but if there is lot of things to process, then it might be worth. Depends on your situation though)

You could also see this thread.

Someone else might come up with a better answer as well...

Edit:

Oh, and btw, if you were going to call those URLs, use @symcbean's answer, about curl_multi_exec I didn't think in that angle at all :p

Community
  • 1
  • 1
Shrinath
  • 7,888
  • 13
  • 48
  • 85
0

There is a way to perform multiple simultaneous requests using the cURL library. Have a look at the curl_multi_ functions.

Sander Bakkum
  • 421
  • 2
  • 7