'Parallel, multiple SOAP requests/connections?
I'm running 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 familiar enough with SOAP to understand how to go about this.
ie: While it's running $client-‐>doStuff(); in the loop, I'd like it to run another resource / connection of the next iteration before the other finishes.
Any ideas? Thank you
Solution 1:[1]
As PHP is a functional language the script waits until $client-?>doStuff(); is finished each time in while loop.
Solution 2:[2]
I would look into Multi-Threading, also this might help.
So using this example you might consider the JobStartAsync() to represent each SOAP request.
PSEUDO Code:
while($i<10) {
JobStartAsync($client = new Client($location, $wsdl, $username, $password),$client?>doStuff());
$i++;
}
Solution 3:[3]
You can Execute SOAP using cURL like this:
And use this PHP class providing an interface for running multiple concurrent CURL requests:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | powtac |
| Solution 2 | Community |
| Solution 3 | Community |
