I've been trying to use httprl to talk HTTPS on port 443 to a third party API, but I'm afraid I've failed. If I use HTTP it's fine but HTTPS connections appear to have a bug somewhere deeper than I tried to find.

The symptom was $chunk = fread($r, $responses[$id]->chunk_size); would be empty, as would $responses[$id]->headers - the end result being I couldn't see the response HTTP codes or the data. The data took two chunks to return when it worked.

The issue was intermittent, I'm not sure if the response was lost or if it wasn't sent. After trying to debug it for a while I switched over to cURL. It seems to only be an issue with HTTPS - HTTP worked fine the whole time.

(I was running the patch in issue #1351238 at the same time)

#6 httprl-1354282-6.patch1008 bytesmikeytown2


mikeytown2’s picture

Do you have the same HTTPS issues with core's drupal_http_request()?

serenecloud’s picture

No, I'm afraid not. I stopped using drupal_http_request because I needed the ability to properly set a timeout time, not because of any issues with the data.

mikeytown2’s picture

Version: 6.x-1.2 » 6.x-1.x-dev

Is there a https site I can test this with?

mikeytown2’s picture

My guess is the 'eof' attribute is getting incorrectly set http://php.net/stream-get-meta-data.

        // Read socket.
        $chunk = fread($r, $responses[$id]->chunk_size);
        if (strlen($chunk) > 0) {
          $rw_done = TRUE;
        $responses[$id]->data .= $chunk;
        // Get stream data.
        $info = stream_get_meta_data($r);


        $alive = !$info['eof'] && !$info['timed_out'] && strlen($chunk);
        if (!$alive) {
          if ($responses[$id]->status == 'in progress') {
            $responses[$id]->status = 'Failed to connect.';
          else {
            $responses[$id]->status = 'Done.';
        else {
          $responses[$id]->status = 'Reading data';

From http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_ht...
Due to PHP bugs like http://bugs.php.net/bug.php?id=43782 and http://bugs.php.net/bug.php?id=46049 we can't rely on feof(), but instead must invoke stream_get_meta_data() each iteration.

I could try http://php.net/feof as the connection is set to closed in httprl.

serenecloud’s picture

The API I've been pointing at is https://api.nzpost.co.nz/tracking If you click the link in "A sample request is available by clicking here." on that page it'll populate the form for you including a guest license key. I've been using JSON to talk to it.

It sounds like you're getting further than I did to finding a solution :) I'll be able to find a bit of time to test a patch for this, but it won't be until about this time next week, I'm coming up against some hard deadlines.

Some different tracking numbers: RA121779505CN, SA547532703NZ, UE131315957NZ and RQ106421698NZ

mikeytown2’s picture

Status: Active » Needs review
1008 bytes

Here's a patch for you to test. I haven't seen it stall till a timeout occurred so that's good.

mikeytown2’s picture

Status: Needs review » Fixed

Above patch has been committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.