You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by Anner van Hardenbroek <dw...@users.sourceforge.net> on 2009/10/24 23:22:49 UTC

[PHP lib] Problem with TBinaryProtocol on Mac OS X

Hi folks!

I've port the server part of the Java lib to PHP, so I've implemented  
a TServerTransport, TServerSocket, TServer, TSimpleServer, etc, and  
I'm testing with a PHP socket server. When I do a request on FreeBSD  
(7.2-RELEASE), it's handled correctly, but when I do a request on Mac  
OS X, the request is not handled correctly. I've modified the  
TBinaryProtocol::readI32() method to give more details on what's  
happening. It boils down to this method, because the problems occur  
right at the beginning of a message.

   public function readI32(&$value) {
     $data = $this->trans_->readAll(4);
     $arr = unpack('N', $data);
     $value = $arr[1];
     var_dump($arr);				// added for debug
     printf("0x%x,0x%x\n", $data, $value);	// added for debug
     if ($value > 0x7fffffff) {
       $value = 0 - (($value - 1) ^ 0xffffffff);
     }
     return 4;
   }

On FreeBSD I got the following output:
> array(1) {
>   [1]=>
>   int(-2147418111)
> }
> 0x0,0x80010001
> array(1) {
>   [1]=>
>   int(8)
> }
> 0x0,0x8
> array(1) {
>   [1]=>
>   int(0)
> }
> 0x0,0x0


On Mac OS X I got the following output:
> array(1) {
>   [1]=>
>   int(2147483647)
> }
> 0x0,0x7fffffff


I think it has something to do with the OS/socket library.
Does anyone have some idea's?

If the community likes the PHP lib server stuff, I can clean up it a  
bit and publish a diff patch somewhere. I'd like also to add some sort  
of threaded server (which only will work on *NIX because the PHP pcntl  
extension).

Kind regards,
Anner.

--
Anner van Hardenbroek
dwlnetnl@users.sourceforge.net