并行,多个SOAP请求/连接?

时间:2011-02-09 14:58:47

标签: php soap parallel-processing

我正在运行以下代码:

<?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++;
    }

?>

单独:

<?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;
}

?>

我想改变它来运行多个连接,可能并行运行,尽管我对SOAP不太熟悉,无法理解如何解决这个问题。

ie:正在运行$ client - &gt; doStuff();在循环中,我希望在另一个迭代完成之前运行下一次迭代的另一个资源/连接。

有什么想法吗?谢谢

3 个答案:

答案 0 :(得分:0)

由于PHP是一种函数式语言,脚本每次在while循环中都会等待$client-­‐>doStuff();完成。

答案 1 :(得分:0)

我会调查Multi-Threadingthis可能会有帮助。

因此,使用this example您可能会认为JobStartAsync()代表每个SOAP请求。

PSEUDO代码:

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

答案 2 :(得分:0)

您可以使用cURL执行SOAP,如下所示:

Execute SOAP using cURL

并使用此PHP类提供运行多个并发CURL请求的接口:

https://github.com/recuweb/ParallelCurl