4

I am making a search widget. when i am searching i am taking results from 2 api's one is from yelp and other is from another source. but this process is taking a longer time

$dataProvider = SearchUtil::locallookup($for, $near); //local api
$content=SearchUtil::yelplookup($for,$near);    //yelp api
$array=array_merge($dataProvider,$content);

Is there any way by which i can call both this api's together? i dont want the yelp api to be called after the first api gives result. i want to call both of them together.

Is there any way to do this ?

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
Mahesh Eu
  • 515
  • 1
  • 6
  • 21

2 Answers2

1

It is possible, but you will have to rewrite both locallookup and yelplookup and tie them both together into a cURL multi_exec context. cURL, by default, runs synchronously. In your case, you want it async on multiple sets of data, and the best way to do it is to run both channels into a multi_exec context.

More info on this page: http://php.net/manual/fr/function.curl-multi-exec.php .

Once you curl_multi_exec(), you will be able to track the status of the set of calls using the second parameter (which will be reference-changed to true or false), and from there, you'll also be able to get the content of each channel using curl_multi_getcontent().

Sébastien Renauld
  • 19,203
  • 2
  • 46
  • 66
1

i have got some results.

http://www.phpied.com/simultaneuos-http-requests-in-php-with-curl/

https://github.com/petewarden/ParallelCurl

may be this will be useful to others..

Mahesh Eu
  • 515
  • 1
  • 6
  • 21