2011-02-09 57 views
4

我运行下面的代码:并行的多个SOAP请求/连接?

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

?> 

我想改变这种运行多个连接,可能并行,虽然我不是用肥皂了解不够熟悉如何去做这件事。

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

任何想法?谢谢

+1

我会研究多线程:http://stackoverflow.com/questions/70855/how-can-one-use-multi-threading-in-php-applications – 2011-02-09 15:04:27

+0

@Phill Pafford:谢谢!看起来像我以后,但不知道如何调整上述来完成示例[link](http://phplens.com/phpeverywhere/?q=node/view/254)中显示的内容,因为它使用fsock 。任何使用SOAP的建议或例子?再次感谢你。 – jeremycollins 2011-02-09 15:10:10

回答

0

由于PHP是一种功能性语言,脚本一直等到$client-­‐>doStuff();每次在while循环中完成。

0

我想看看Multi-Threadingthis也许会有所帮助。

因此使用this example您可能会考虑JobStartAsync()来表示每个SOAP请求。

伪代码:

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