Hi,

I just tried to save a node of a special content type and got this error:

    * warning: file_get_contents(http://api.bit.ly/shorten?version=2.0.1&format=xml&history=1&login=MYLOGIN&apiKey=MYAPI-KEY&longUrl=http://www.MY-SITE.com/ernaehrungstagebuch/tobias/mein-einag-in-ernaehrungstagebuh): failed to open stream: HTTP request failed! in /srv/www/vhosts/MY-SITE.com/httpdocs/sites/all/modules/shorten/shorten.module on line 324.

    * warning: strpos(): Offset not contained in string in /srv/www/vhosts/MYSITE.com/httpdocs/sites/all/modules/shorten/shorten.module on line 361.

Any idea what this is???? It seems to appear just with this one content type because while I puplished nodes of other content types no error message appeared.

Greez,
Tobias

Comments

tobiberlin’s picture

I installed Taxonomy Autotagger and since then this error message appears. Obviously there is no connection created to the bit-ly service as I realized that within an automatically published Tweet on my Twitter account using rules and the [node:url]-token the original URL is used not the shortened one. Could it be that Shorten URL and Autotag are intefering?

tobiberlin’s picture

Title: Error message when creating a special content type » Error message caused by Taxonomy Autotagger module?
tobiberlin’s picture

Title: Error message caused by Taxonomy Autotagger module? » Error message

Ok... I realized that this error message appears as well with a project on which Autotag is not installed... :-(

icecreamyou’s picture

Category: bug » support
Status: Active » Fixed

Try it with a URL shortening service other than bit.ly. Also try shortening a URL from example.com/shorten. If it doesn't work, your server probably doesn't support filestreams, which is extremely unusual but means that you won't be able to use the Shorten URLs module. If the option is available in your settings, use cURL instead, but I would be surprised if you have cURL and not filestreams.

tobiberlin’s picture

The module worked just fine during a longer time and suddenly started to fail. Maybe it has something to do with bit.ly - I just changed the service to "This site" and it seems to work fine now. Thank you for your support.

Status: Fixed » Closed (fixed)

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

alan d.’s picture

Just confirming that this is a bug in the code from version 6.x-1.5, but I am not reopening as I haven't looked at HEAD to see recent changes.

The module should test the result from any service and if NULL / FALSE (aka no curl support or open remote files), it should not cache the result and return the original URL.

<?php
    // Untested example of standard surl request
    $contents = curl_exec($c);
    if (curl_error($c)) {
      // And maybe some watchdog logs - cURL can be problematic
      $contents = $url;
    }    
    curl_close($c);


   And latter

  if ($org_url != $shortened_url) {
    # caching
  }
  return $shortened_url;
?>

Cheers

icecreamyou’s picture

When an attempt to shorten a URL fails, Shorten URLs 6.x-1.6 and later only caches the original URL for 30 minutes. (When shortening succeeds, the URL is cached for 3 weeks.)

alan d.’s picture

Cool, but the code from 1.5 was throwing errors, with cURL enable, cURL selected, but server configuration meaning that the cURL request itself failed. [edit: the FALSE result was being passed to string functions]

icecreamyou’s picture

Sucks.

  • 1.5 is not supported
  • There's nothing I can do if your server is not properly configured
  • I can't even begin to postulate about how to fix your errors if you don't even tell me exactly what the error messages were
  • This thread is closed and should only be continued if you have exactly the same problem as the original poster

...and now that I'm done being snarky, you're actually totally right, when cURL fails FALSE could get passed to drupal_substr(). I just fixed that in dev. :-P

alan d.’s picture

Sorry for trying to help eliminate the same error as in:

warning: strpos(): Offset not contained in string in /srv/www/vhosts/MYSITE.com/httpdocs/sites/all/modules/shorten/shorten.module on line XXX.

which was the direct result of a cURL request that had an error. It returns FALSE and not a string if cURL itself has an error. Simple really, same as file_get_contents() or whatever you use with the file() approach. A network error will result in the same response from either method and both continue on unchecked into the parsing functions that expect a string and then trigger off the error. So I hope the check you implemented was on both....

Anyway, enough time on this.

icecreamyou’s picture

Version: 6.x-1.5 » 6.x-1.x-dev
Status: Closed (fixed) » Active

I'm just being sarcastic, I don't mean any offense. You were right, there was a problem. I thought I fixed it yesterday but it turns out I missed another place where the problem could happen, in _shorten_xml() which only gets run for bit.ly, j.mp, and retwt.me. I'm not at my desk but I'll fix that later today.

icecreamyou’s picture

Status: Active » Fixed

Committed to dev. Thanks for the report.

alan d.’s picture

:)

Thanks for the module by the way. It does the job nicely!

Status: Fixed » Closed (fixed)

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