4

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

jeremycollins
  • 379
  • 3
  • 10
  • 17
  • 1
    I would look into multi-threading: http://stackoverflow.com/questions/70855/how-can-one-use-multi-threading-in-php-applications – Phill Pafford Feb 09 '11 at 15:04
  • @Phill Pafford: Thanks! Looks like what I was after, but no idea how to adjust the above to accomplish what is shown in the example [link](http://phplens.com/phpeverywhere/?q=node/view/254) as it uses fsock. Any suggestions or examples in using SOAP? Thank you again. – jeremycollins Feb 09 '11 at 15:10
  • You may want to look at this: http://www.php.net/manual/en/function.fsockopen.php#64094 – Phill Pafford Feb 09 '11 at 16:45
  • @Phill Pafford: Looking more like it.. basically fsockopen, run SOAP connection, then close. How could I adjust the above code to fit in with the fsockopen example? (any help with cut and paste code in the right areas would be VERY appreciated) Sorry, extremely new to this. Thanks!! – jeremycollins Feb 09 '11 at 17:08
  • @Phill Pafford: Please also add anything further to your own answer so I can accept your solution :) Thanks – jeremycollins Feb 09 '11 at 17:09

3 Answers3

0

You can Execute SOAP using cURL like this:

Execute SOAP using cURL

And use this PHP class providing an interface for running multiple concurrent CURL requests:

https://github.com/recuweb/ParallelCurl

Community
  • 1
  • 1
RafaSashi
  • 16,483
  • 8
  • 84
  • 94
0

As PHP is a functional language the script waits until $client-­‐>doStuff(); is finished each time in while loop.

powtac
  • 40,542
  • 28
  • 115
  • 170
  • Thanks for the info! So what could I possibly do to speed up each 'doStuff' function? I thought multi-threading would be the only way.. – jeremycollins Feb 09 '11 at 15:24
  • as Phill Pafford said, check for multithreading and activate the wsdl caching. – powtac Feb 09 '11 at 15:25
  • Not a problem. I have updated the original code which may give you a better insight into what I am dealing with, in regards to the resource/connection. You still suggest multithreading and wsdl caching? – jeremycollins Feb 09 '11 at 15:32
0

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++;
}
Community
  • 1
  • 1
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383