Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

file_get_contents - failed to open stream

1 view
Skip to first unread message

koichirose

unread,
Dec 19, 2009, 2:31:54 PM12/19/09
to
I'm using the exact same piece of code on two different servers (it's
to shorten an url via bit.ly):
function shorten($url)

{

$response=json_decode(file_get_contents('http://api.bit.ly/shorten?
version=2.0.1&longUrl='.$url.'&login='.$this->user.'&apiKey='.$this-
>api),TRUE);

return array('url' => $response['results'][$url]['shortUrl'], 'hash'
=> $response['results'][$url]['hash']);

}

This works on a machine, doesn't on another. Both have curl enabled
and allow_url_fopen set to 'on' and user_agent with no value.
The error is 'failed to open stream: HTTP request failed!'

How can I solve this? Thanks

Luuk

unread,
Dec 19, 2009, 3:36:50 PM12/19/09
to
Op 19-12-2009 20:31, koichirose schreef:

it seems that you cannot solve this (that why you ask... ;-)

http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen

besides the 'allow_url_fopen' to 'on' check the other settings given
there...

--
Luuk

C. (http://symcbean.blogspot.com/)

unread,
Dec 21, 2009, 8:30:53 AM12/21/09
to
On Dec 19, 8:36 pm, Luuk <l...@invalid.lan> wrote:
> Op 19-12-2009 20:31, koichirose schreef:
>
>
>
> > I'm using the exact same piece of code on two different servers (it's
> > to shorten an url via bit.ly):
> > function shorten($url)
>
> >    {
>
> >            $response=json_decode(file_get_contents('http://api.bit.ly/shorten?
> > version=2.0.1&longUrl='.$url.'&login='.$this->user.'&apiKey='.$this-
> >> api),TRUE);
>
> >            return array('url' => $response['results'][$url]['shortUrl'], 'hash'
> > => $response['results'][$url]['hash']);
>
> >    }
>
> > This works on a machine, doesn't on another. Both have curl enabled
> > and allow_url_fopen set to 'on' and user_agent with no value.
> > The error is 'failed to open stream: HTTP request failed!'
>
> > How can I solve this? Thanks
>
> it seems that you cannot solve this (that why you ask...  ;-)
>
> http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-u...

>
> besides the 'allow_url_fopen' to 'on' check the other settings given
> there...
>
> --
> Luuk

It also pre-supposes that the server can make outgoing DNS lookups and
HTTP connections.

C.

0 new messages