You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Simon Chu <si...@gmail.com> on 2009/09/18 19:14:42 UTC

generated php code, what are the values of the constructor param?

class SimonSaysClient implements SimonSaysIf {
  protected $input_ = null;
  protected $output_ = null;

  protected $seqid_ = 0;

  public function __construct($input, $output=null) {
    $this->input_ = $input;
    $this->output_ = $output ? $output : $input;
  }


The above code was generated, what are the expected values of $input and
$output?  I put in the facebook thrift server name (with or without the
port) as $input got this error:

PHP Fatal error:  Call to a member function writeMessageBegin() on a
non-object in
/home/simon/PROG/PHP/UTILITY/trunk/facebook/simonsays/SimonSays.php on line
47

Re: generated php code, what are the values of the constructor param?

Posted by Samir Mulder <sa...@gmail.com>.
Also before making a server call you'll need to open the transport.  
Like:

$transport->open();
$rec = $client->someFunction(whatever arguments...);
print $rec . "\n";

$transport->close();

Hope this helps.

Samir

On Sep 18, 2009, at 10:18 AM, Samir Mulder wrote:

> You need to pass in a protocol object. Like:
>
> $socket = new Socket('localhost', 5013);
> $transport = new BufferedTransport($socket, 1024, 1024);
> $protocol = new BinaryProtocol($transport);
> $client = new SimonSaysClient($protocol);
>
> I'm not using the latest Thrift but I assume this hasn't changed.
>
> Thanks.
>
> Samir
>
> On Sep 18, 2009, at 10:14 AM, Simon Chu wrote:
>
>> class SimonSaysClient implements SimonSaysIf {
>> protected $input_ = null;
>> protected $output_ = null;
>>
>> protected $seqid_ = 0;
>>
>> public function __construct($input, $output=null) {
>>   $this->input_ = $input;
>>   $this->output_ = $output ? $output : $input;
>> }
>>
>>
>> The above code was generated, what are the expected values of  
>> $input and
>> $output?  I put in the facebook thrift server name (with or without  
>> the
>> port) as $input got this error:
>>
>> PHP Fatal error:  Call to a member function writeMessageBegin() on a
>> non-object in
>> /home/simon/PROG/PHP/UTILITY/trunk/facebook/simonsays/SimonSays.php  
>> on line
>> 47
>


Re: generated php code, what are the values of the constructor param?

Posted by Samir Mulder <sa...@gmail.com>.
You need to pass in a protocol object. Like:

$socket = new Socket('localhost', 5013);
$transport = new BufferedTransport($socket, 1024, 1024);
$protocol = new BinaryProtocol($transport);
$client = new SimonSaysClient($protocol);

I'm not using the latest Thrift but I assume this hasn't changed.

Thanks.

Samir

On Sep 18, 2009, at 10:14 AM, Simon Chu wrote:

> class SimonSaysClient implements SimonSaysIf {
>  protected $input_ = null;
>  protected $output_ = null;
>
>  protected $seqid_ = 0;
>
>  public function __construct($input, $output=null) {
>    $this->input_ = $input;
>    $this->output_ = $output ? $output : $input;
>  }
>
>
> The above code was generated, what are the expected values of $input  
> and
> $output?  I put in the facebook thrift server name (with or without  
> the
> port) as $input got this error:
>
> PHP Fatal error:  Call to a member function writeMessageBegin() on a
> non-object in
> /home/simon/PROG/PHP/UTILITY/trunk/facebook/simonsays/SimonSays.php  
> on line
> 47


Re: generated php code, what are the values of the constructor param?

Posted by bill fumerola <bi...@mu.org>.
On Fri, Sep 18, 2009 at 11:07:10AM -0700, Simon Chu wrote:
> i)  is the C, cpp interface similar, please give example

c++ interface is as identical as a php and c++ implementation can be.

shared_ptr<TSocket> socket (new TSocket(host, port));
shared_ptr<TTransport> transport (new TBufferedTransport(socket);
shared_ptr<TProtocol> protocol (new TBinaryProtocol(transport));
shared_ptr<myClient> client (new myClient(protocol);

try {
  transport->open();
  int ret = client->someCallReturnsInt();
} catch (exception &e) {
  cout << "exception: " << e.what() << endl;
}

> ii)  I got further.  Where is TException defined?  What is the method to
> print out exception message?

TException inherits from Exception.

http://svn.apache.org/repos/asf/incubator/thrift/trunk/lib/php/src/Thrift.php

http://us2.php.net/manual/en/language.exceptions.php

e.g.
try {
  $transport->open();
} catch (Exception $e) {
  echo $e->getMessage();
}


-- bill

Re: generated php code, what are the values of the constructor param?

Posted by Simon Chu <si...@gmail.com>.
i)  is the C, cpp interface similar, please give example

ii)  I got further.  Where is TException defined?  What is the method to
print out exception message?

Got the following:
PHP Warning:  stream_set_timeout(): supplied argument is not a valid stream
resource in
/home/simon/PROG/PHP/UTILITY/trunk/facebook/thrift/transport/TSocket.php on
line 281
PHP Warning:  stream_get_meta_data(): supplied argument is not a valid
stream resource in
/home/simon/PROG/PHP/UTILITY/trunk/facebook/thrift/transport/TSocket.php on
line 287
Failed registeringPHP Fatal error:  Call to undefined method
TException::message() in
/home/simon/PROG/PHP/UTILITY/trunk/facebook/simonsays/ss.php on line 41


On Fri, Sep 18, 2009 at 10:19 AM, Patrick Schlangen <p....@me.com>wrote:

> Hi,
>
> $input has to be the protocol class instance.
>
> Example:
>
>        $socket                 = new TSocket($host, $port);
>        $transport              = new TBufferedTransport($socket);
>        $protocol               = new TBinaryProtocol($transport);
>        $client                 = new SimonSaysClient($protocol);
>        $transport->open();
>
>        // use $client
>
>        $transport->close();
>
> --
> Patrick Schlangen
> p.schlangen@me.com
>
>
>
> Am 18.09.2009 um 19:14 schrieb Simon Chu:
>
>
>  class SimonSaysClient implements SimonSaysIf {
>>  protected $input_ = null;
>>  protected $output_ = null;
>>
>>  protected $seqid_ = 0;
>>
>>  public function __construct($input, $output=null) {
>>   $this->input_ = $input;
>>   $this->output_ = $output ? $output : $input;
>>  }
>>
>>
>> The above code was generated, what are the expected values of $input and
>> $output?  I put in the facebook thrift server name (with or without the
>> port) as $input got this error:
>>
>> PHP Fatal error:  Call to a member function writeMessageBegin() on a
>> non-object in
>> /home/simon/PROG/PHP/UTILITY/trunk/facebook/simonsays/SimonSays.php on
>> line
>> 47
>>
>
>

Re: generated php code, what are the values of the constructor param?

Posted by Patrick Schlangen <p....@me.com>.
Hi,

$input has to be the protocol class instance.

Example:
	
	$socket			= new TSocket($host, $port);
	$transport 		= new TBufferedTransport($socket);
	$protocol 		= new TBinaryProtocol($transport);
	$client 		= new SimonSaysClient($protocol);
	$transport->open();

	// use $client

	$transport->close();

--
Patrick Schlangen
p.schlangen@me.com



Am 18.09.2009 um 19:14 schrieb Simon Chu:

> class SimonSaysClient implements SimonSaysIf {
>  protected $input_ = null;
>  protected $output_ = null;
>
>  protected $seqid_ = 0;
>
>  public function __construct($input, $output=null) {
>    $this->input_ = $input;
>    $this->output_ = $output ? $output : $input;
>  }
>
>
> The above code was generated, what are the expected values of $input  
> and
> $output?  I put in the facebook thrift server name (with or without  
> the
> port) as $input got this error:
>
> PHP Fatal error:  Call to a member function writeMessageBegin() on a
> non-object in
> /home/simon/PROG/PHP/UTILITY/trunk/facebook/simonsays/SimonSays.php  
> on line
> 47