一个请求后,PHP SoapClient失败

时间:2014-09-30 18:42:24

标签: php soap

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

我认为这个问题可能与我的服务器配置有关,因为相同的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;
  }
}

?>

1 个答案:

答案 0 :(得分:2)

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

PHP Download Link