1
 foreach ($items as $k=>$value) {
    $valuesChunk = array_chunk($value, 1000);
    foreach ( $valuesChunk as $chunk){
       //call a web service for this chunk
       $ws = WS::getItems($chunk);
       //time response 20 seconds 
   }
 }

For example if I want to execute this code for 10000 items it takes 10 X 20 seconds.

Can I execute all the webservice calls in parallel to reduce the response time?

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • I tried to correct your grammar as much as I could, but I don't really know what `in sometimes` means? Do you mean execute the requests in parallel (i.e. at the same time as each other), maybe? – ADyson Jul 08 '21 at 15:03
  • Yes exactly in parallel – Ismail Elmanti Jul 08 '21 at 15:07
  • Ok I edited it again. PHP has extremely poor support for asynchronous programming in the way you're describing unfortunately, but https://stackoverflow.com/questions/9308779/php-parallel-curl-requests might help you, assuming you're using curl inside your `WS` class – ADyson Jul 08 '21 at 15:10
  • There exists async frameworks that you can utilize to write non-blocking solutions. Have a look at [AMPHP](https://amphp.org/). – Code4R7 Jul 08 '21 at 17:20

0 Answers0