Brij Raj Singh - MSFT
Brij Raj Singh - MSFT

Reputation: 5113

Uncaught TTransportException' with message 'THttpClient: Could not read 1936027957 bytes in THttpClient.php:162

This is my thrift definition

namespace php mobiledata

struct sms
{
    1: string from,
    2: string to,
    3: string smstext,
    4: string smsdatetime,
    5: string smsdirection
}

struct smsdetails
{
    1: list<sms> smsdata
}

service mobiledataservice
{
    void insertsmsdata (1: smsdetails smslist)
}

The php type generated by the thrift in Types.php is

<?php
namespace mobiledata;

/**
 * Autogenerated by Thrift Compiler (1.0.0-dev)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
use Thrift\Base\TBase;
use Thrift\Type\TType;
use Thrift\Type\TMessageType;
use Thrift\Exception\TException;
use Thrift\Exception\TProtocolException;
use Thrift\Protocol\TProtocol;
use Thrift\Protocol\TBinaryProtocolAccelerated;
use Thrift\Exception\TApplicationException;


class sms {
  static $_TSPEC;

  /**
   * @var string
   */
  public $from = null;
  /**
   * @var string
   */
  public $to = null;
  /**
   * @var string
   */
  public $smstext = null;
  /**
   * @var string
   */
  public $smsdatetime = null;
  /**
   * @var string
   */
  public $smsdirection = null;

  public function __construct($vals=null) {
    if (!isset(self::$_TSPEC)) {
      self::$_TSPEC = array(
        1 => array(
          'var' => 'from',
          'type' => TType::STRING,
          ),
        2 => array(
          'var' => 'to',
          'type' => TType::STRING,
          ),
        3 => array(
          'var' => 'smstext',
          'type' => TType::STRING,
          ),
        4 => array(
          'var' => 'smsdatetime',
          'type' => TType::STRING,
          ),
        5 => array(
          'var' => 'smsdirection',
          'type' => TType::STRING,
          ),
        );
    }
    if (is_array($vals)) {
      if (isset($vals['from'])) {
        $this->from = $vals['from'];
      }
      if (isset($vals['to'])) {
        $this->to = $vals['to'];
      }
      if (isset($vals['smstext'])) {
        $this->smstext = $vals['smstext'];
      }
      if (isset($vals['smsdatetime'])) {
        $this->smsdatetime = $vals['smsdatetime'];
      }
      if (isset($vals['smsdirection'])) {
        $this->smsdirection = $vals['smsdirection'];
      }
    }
  }

  public function getName() {
    return 'sms';
  }

  public function read($input)
  {
    $xfer = 0;
    $fname = null;
    $ftype = 0;
    $fid = 0;
    $xfer += $input->readStructBegin($fname);
    while (true)
    {
      $xfer += $input->readFieldBegin($fname, $ftype, $fid);
      if ($ftype == TType::STOP) {
        break;
      }
      switch ($fid)
      {
        case 1:
          if ($ftype == TType::STRING) {
            $xfer += $input->readString($this->from);
          } else {
            $xfer += $input->skip($ftype);
          }
          break;
        case 2:
          if ($ftype == TType::STRING) {
            $xfer += $input->readString($this->to);
          } else {
            $xfer += $input->skip($ftype);
          }
          break;
        case 3:
          if ($ftype == TType::STRING) {
            $xfer += $input->readString($this->smstext);
          } else {
            $xfer += $input->skip($ftype);
          }
          break;
        case 4:
          if ($ftype == TType::STRING) {
            $xfer += $input->readString($this->smsdatetime);
          } else {
            $xfer += $input->skip($ftype);
          }
          break;
        case 5:
          if ($ftype == TType::STRING) {
            $xfer += $input->readString($this->smsdirection);
          } else {
            $xfer += $input->skip($ftype);
          }
          break;
        default:
          $xfer += $input->skip($ftype);
          break;
      }
      $xfer += $input->readFieldEnd();
    }
    $xfer += $input->readStructEnd();
    return $xfer;
  }

  public function write($output) {
    $xfer = 0;
    $xfer += $output->writeStructBegin('sms');
    if ($this->from !== null) {
      $xfer += $output->writeFieldBegin('from', TType::STRING, 1);
      $xfer += $output->writeString($this->from);
      $xfer += $output->writeFieldEnd();
    }
    if ($this->to !== null) {
      $xfer += $output->writeFieldBegin('to', TType::STRING, 2);
      $xfer += $output->writeString($this->to);
      $xfer += $output->writeFieldEnd();
    }
    if ($this->smstext !== null) {
      $xfer += $output->writeFieldBegin('smstext', TType::STRING, 3);
      $xfer += $output->writeString($this->smstext);
      $xfer += $output->writeFieldEnd();
    }
    if ($this->smsdatetime !== null) {
      $xfer += $output->writeFieldBegin('smsdatetime', TType::STRING, 4);
      $xfer += $output->writeString($this->smsdatetime);
      $xfer += $output->writeFieldEnd();
    }
    if ($this->smsdirection !== null) {
      $xfer += $output->writeFieldBegin('smsdirection', TType::STRING, 5);
      $xfer += $output->writeString($this->smsdirection);
      $xfer += $output->writeFieldEnd();
    }
    $xfer += $output->writeFieldStop();
    $xfer += $output->writeStructEnd();
    return $xfer;
  }

}

class smsdetails {
  static $_TSPEC;

  /**
   * @var \mobiledata\sms[]
   */
  public $smsdata = null;

  public function __construct($vals=null) {
    if (!isset(self::$_TSPEC)) {
      self::$_TSPEC = array(
        1 => array(
          'var' => 'smsdata',
          'type' => TType::LST,
          'etype' => TType::STRUCT,
          'elem' => array(
            'type' => TType::STRUCT,
            'class' => '\mobiledata\sms',
            ),
          ),
        );
    }
    if (is_array($vals)) {
      if (isset($vals['smsdata'])) {
        $this->smsdata = $vals['smsdata'];
      }
    }
  }

  public function getName() {
    return 'smsdetails';
  }

  public function read($input)
  {
    $xfer = 0;
    $fname = null;
    $ftype = 0;
    $fid = 0;
    $xfer += $input->readStructBegin($fname);
    while (true)
    {
      $xfer += $input->readFieldBegin($fname, $ftype, $fid);
      if ($ftype == TType::STOP) {
        break;
      }
      switch ($fid)
      {
        case 1:
          if ($ftype == TType::LST) {
            $this->smsdata = array();
            $_size0 = 0;
            $_etype3 = 0;
            $xfer += $input->readListBegin($_etype3, $_size0);
            for ($_i4 = 0; $_i4 < $_size0; ++$_i4)
            {
              $elem5 = null;
              $elem5 = new \mobiledata\sms();
              $xfer += $elem5->read($input);
              $this->smsdata []= $elem5;
            }
            $xfer += $input->readListEnd();
          } else {
            $xfer += $input->skip($ftype);
          }
          break;
        default:
          $xfer += $input->skip($ftype);
          break;
      }
      $xfer += $input->readFieldEnd();
    }
    $xfer += $input->readStructEnd();
    return $xfer;
  }

  public function write($output) {
    $xfer = 0;
    $xfer += $output->writeStructBegin('smsdetails');
    if ($this->smsdata !== null) {
      if (!is_array($this->smsdata)) {
        throw new TProtocolException('Bad type in structure.', TProtocolException::INVALID_DATA);
      }
      $xfer += $output->writeFieldBegin('smsdata', TType::LST, 1);
      {
        $output->writeListBegin(TType::STRUCT, count($this->smsdata));
        {
          foreach ($this->smsdata as $iter6)
          {
            $xfer += $iter6->write($output);
          }
        }
        $output->writeListEnd();
      }
      $xfer += $output->writeFieldEnd();
    }
    $xfer += $output->writeFieldStop();
    $xfer += $output->writeStructEnd();
    return $xfer;
  }

}

In the client I am sending the data by making objects like

  $transport->open();

$smsobj = new sms();
$smsobj->from = "9999074909";
$smsobj->to = "9999074909";
$smsobj->smstext = "hello brij";
$smsobj->smsdatetime = "today";
$smsobj->smsdirection = "I";

$smsdetailsobj  = new smsdetails();
$smsdetailsobj->smsdata = array($smsobj);

var_dump(array($smsobj));

$client->insertsmsdata($smsdetailsobj);

  $transport->close();

I get this error when I run the client

PHP Fatal error:  Uncaught exception 'Thrift\Exception\TTransportException' with message 'THttpClient: Could not read 1936027957 bytes from localhost:80/phpserver/php-server.php' in thrift/thrift/lib/php/lib/Thrift/Transport/THttpClient.php:162
Stack trace:

Looks like I am not making my php client object right, is this how i should make a list of struct objects with php - like array of objects of sms type.

Upvotes: 1

Views: 1693

Answers (1)

JensG
JensG

Reputation: 13411

The by far most frequent cause is an incompatible transport/protocol stack, specifically a Server expecting TFramedTransport and a Client not using TFramedTransport.

You have to make sure that both sides use the exact same stack with respect to wire format. As a rule of thumb, start with the same components on each side.

Slight caveat: A number of server types (e.g. Nonblocking) imply TFramedTransport to be used on the client side, even if this has not explicitly been added to the server protocol/transport stack.

Upvotes: 1

Related Questions