Results 1 to 2 of 2

Thread: Connecting to remote servers (PHP / Thrift)

  1. #1
    Join Date
    Mar 2004

    Default Connecting to remote servers (PHP / Thrift)

    Is anyone using the Thrift libraries -- or anything else calling out to another server from here ?

    I’m working with the EverNote SDK (PHP) and I have not been able to receive remote data. Everything works fine on both my local server and another server, but even a stripped down version of the sample app fails here.

    PHP Code:
    = new THttpClient('''443'"/edam/user"'https');
    $userStoreProtocol = new TBinaryProtocol($userStoreHttpClient);
    $userStore = new UserStoreClient($userStoreProtocol$userStoreProtocol);

    // do something simple and check the protocol version (returns true or false).
    $versionOK $userStore->checkVersion("Evernote EDAMTest (PHP)"121);

    //  <----- it never returns here. But gets stuck reading in ttransport.php
    I’m convinced it’s something with the environment, but what?
    Last edited by chrisd; 07-19-2012 at 08:11 PM.

  2. #2
    Join Date
    Mar 2004


    In case there's a second person on this planet trying to figure this out, THRIFT or otherwise, it appears to be an issue with PHP's stream_context_create and inserting HTTP headers.

    Specifically I needed to POST "Content-Type: application/x-thrift" to the remote server, and although I was inserting the headers properly, they were being stripped and/or overridden on the way out.

    There's a post at that pushed my in the right direction, and as a workaround I'm now using:
    PHP Code:
    ini_set("user_agent""PHP/THttpClient\r\nAccept: application/x-thrift\r\nContent-Type: application/x-thrift"); 
    Appending to the user-agent gets us the rest of the headers as a bonus (if not a bit ugly).

    FWIW, here's THRIFT'S implementation (from THttpClient.php) that was failing:
    PHP Code:
        $headers = array('Host: '.$host,
    'Accept: application/x-thrift',
    'User-Agent: PHP/THttpClient',
    'Content-Type: application/x-thrift',
    'Content-Length: '.strlen($this->buf_));

    $options = array('method' => 'POST''protocol_version' => 1.1,
    'header' => implode("\r\n"$headers),
    'max_redirects' => 1,
    'content' => $this->buf_);
    $this->buf_ '';

    $contextid stream_context_create(array('http' => $options));
    $this->handle_ = @fopen($this->scheme_.'://'.$host.$this->uri_'r'false$contextid); 
    I'm still completely baffed as to why this is happening, but at least now we can deal with it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts