2014-09-30 89 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