In parallel, multiple SOAP requests / connections?

I run the following code:

<?php $i=0; // connection credentials and settings $location = 'https://url.com/'; $wsdl = $location.'?wsdl'; $username = 'user'; $password = 'pass'; // create client resource - connection $client = new Client($location, $wsdl, $username, $password); // do stuff while($i<10) { $client-‐>doStuff(); echo $client‐>response(); $i++; } ?> 

Separately:

 <?php public function doStuff() { $this->response = $this->srv()->doStuff(array('stuff' => $this->get('stuff'))); return $this; } public function __construct($location, $wsdl, $username, $password, $proxyHost = NULL, $proxyPort = NULL) { if(is_null($proxyHost) || is_null($proxyPort)) $connection = new SoapClient($wsdl, array('login' => $username, 'password' => $password)); else $connection = new SoapClient($wsdl, array('login' => $username, 'password' => $password, 'proxy_host' => $proxyHost, 'proxy_port' => $proxyPort)); $connection->__setLocation($location); $this->connection = $connection; return $this->connection; } public function srv() { return $this->connection; } ?> 

I wanted to change this to run multiple connections, possibly in parallel, although I am not good at SOAP to understand how to do this.

i.e.: when running $ client β†’ doStuff (); in a loop, I would like it to start another resource / connection of the next iteration before another ends.

Any ideas? thank you

+4
source share
3 answers

Since PHP is a functional language, the script waits for $client-‐>doStuff(); will not be completed every time during the cycle.

0
source

I would look at Multi-Threading , and also this one could help.

Thus, using this example , you can consider JobStartAsync () to represent each SOAP request.

PSEUDO Code:

 while($i<10) { JobStartAsync($client = new Client($location, $wsdl, $username, $password),$client‐>doStuff()); $i++; } 
0
source

You can perform SOAP with cURL as follows:

Performing SOAP using cURL

And use this PHP class, which provides an interface to run multiple simultaneous CURL requests:

https://github.com/recuweb/ParallelCurl

0
source

Source: https://habr.com/ru/post/1339043/


All Articles