一个请求后 PHP SoapClient 失败

标签 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;
  }
}

?>

最佳答案

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

PHP Download Link

关于一个请求后 PHP SoapClient 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26127860/

相关文章:

javascript - 在PDO的JS代码中使用PHP数组

Java WebServices 和 WSDL 文件生成

web-services - SEI 和 WSDL 有什么区别

PHP 解析来自 SOAP 客户端的 SOAP XML 响应

c# - 如何在 C# 中复制 PHP 的 PRNG 算法实现?

php - 如何在 CLI 中运行 laravel 程序?

php - 列出 channel 中已安装的包

php - Android 和 HTML 页面之间的 Webview 数据不匹配

java - 如何使用 Web 服务传递对象等复杂类型?

java - Jax-ws : Java SOAP exception :MustUnderstand headers:[{http://www. w3.org/2005/08/addressing} Action