2014-09-30 92 views
4

我有一个使用SoapClient访问API的PHP脚本。连接后,如果我只提出一个请求,它会按预期工作,但当我尝试使用相同的SoapClient对象发出第二个请求时,出现Bad Request错误。PHP SoapClient在一次请求后失败

我认为这个问题可能与我的服务器配置有关,因为相同的PHP代码在另一台具有旧版本PHP的计算机上正常工作,但在已更新到PHP 5.6的测试和生产服务器上都遇到此错误。

代码:

<?php 

class ReportAPI 
{ 
    protected $reportDataObject = null; 

    public function __construct($url = 'URL', $username = 'username', $password = 'pass') { 
    $this->client = new SoapClient($url , array('login' => $username, 'password' => $password, 'keep_alive' => true)); 
    } 
    public function getReportData($reportID) { 
    return $this->getDataObject($reportID)->data; 
    } 
    public function getReportCount($reportID) { 
    return $this->getDataObject($reportID)->result_count; 
    } 
    public function runReport($reportID) { 
    $newID = $this->client->runReport($reportID); 
    $counter = 0; 
    while($this->client->checkReportRun($newID) != 'complete'){ 
     if($counter > 2) { 
     throw new Exception('Report Time Out'); 
     } 
     sleep(5); 
     $counter++; 
    } 
    $this->getDataObject($newID); 
    return $newID; 
    } 

    public function functest() { 
    $v0 = $this->getDataObject('id')->result_count; 
    return $this->getDataObject('id')->data; 
    } 

    public function getLatestID($reportID) { 
    $runlist = $this->client->getReportRunList($reportID); 
    return $runlist[0][0]; 
    } 

    public function getLatestReportData($reportID) { 
    return $this->getReportData($this->getLatestID($reportID)); 
    } 

    public function getTitles($reportID) { 
    return $this->getDataObject($reportID)->columns; 
    } 

    public function getReportRunTime($reportID) { 
    $runlist = $this->client->getReportRunList($reportID); 
    return strtotime($runlist[0][2]); 
    } 

    public function getRawReport($reportID) { 
    return $this->client->getReportDataObject($reportID); 
    } 

    protected function getDataObject($reportID) { 
    if(!isset($this->reportDataObject) || $this->reportDataObject->report_run_id != $reportID) { 
     $this->reportDataObject = $this->client->getReportDataObject($reportID); 
    } 
    return $this->reportDataObject; 
    } 
} 

?> 
+0

作为一个想后,我尝试添加了KEEP_ALIVE选项将SoapClient的,但它并没有帮助。 – latca 2014-09-30 18:45:14

+0

你的代码是什么样的? – 2014-09-30 19:07:12

+0

@Concolato先生:我编辑了这篇文章并添加了它。谢谢! – latca 2014-09-30 19:57:24

回答

2

此问题已修复在PHP 5.6.1。尽管在更改日志中找不到任何对此问题的引用,但在安装5.6.1之后,我可以重用SoapClient对象并执行后续的__doRequest()调用。

PHP Download Link

+0

太棒了!我会测试一下。我最终回到了以前的5.4版本,但我会测试最新的更新。谢谢。 – latca 2014-10-07 16:46:35

+0

@latca,如果这不会帮助,给我的HTTP请求和响应XML的: '尝试{ ... }赶上(\贝哈特\贝哈特\异常\除外){ 的var_dump(阵列( '请求' => $ client - > __ getLastRequest(), 'requestHeaders'=> $ client - > __ getLastRequestHeaders(), 'response'=> $ client - > __ getLastResponse(), 'responseHeaders'=> $ client - > __ getLastResponseHeaders() ) )); }' – 2014-10-08 18:26:36

+1

这个错误可能是:https://bugs.php.net/bug.php?id = 67955 - 它被列在更改日志中http://php.net/ChangeLog-5.php#5.6 .1根据SOAP – hakre 2014-10-09 22:44:15