2

When I call http_get it never returns, my WEB page just stops outputting at that point. The destination URL never gets the request.

<?php           //simplest test of http_get I could make
    print "http://kayaker.net/php/image.php?id=ORCS084144<br>";
    http_get ("http://kayaker.net/php/image.php?id=ORCS084144");
    print "<br>back from http_get<br>";
?>

The original script was calling http_get in a loop to send data to several other processes on another server.
The loop stops on the first call to http_get. I tried calling flush(); after every line printed, no joy. I tried setting longer timeouts in the $options parameter to http_get, that didn't help. I tried calling http_request with HTTP_METH_GET in the first argument, same problem.

This kayaker URL is not the original, just a shorter example that still fails. I took one of the original URLs and pasted it into my browser address line, it worked fine. I pasted some of the original URLs into another scripting language (The llHTTPRequest function in LSL on Open Simulator) and they work fine from there.

I stored the program above at a location where you can run it from your browser and see it fail.
I pasted the URL to the program above into another scripting language and that at least returned an error status (500) and a message "Internal Server Error" which probably just means the test program didn't terminate properly.

I must be doing something very simple stupid and basically wrong.
But what is it?

Alex Andrei
  • 7,315
  • 3
  • 28
  • 42
Mike Higgins
  • 151
  • 5

2 Answers2

0

Problem

You do not seem to have the right package installed (PECL pecl_http >= 0.1.0).

Fatal error: Call to undefined function http_get() in [snip] on line 8

Solution

You can either

  • install pecl_http as described in the documentation.

  • use a different function as mentioned in the comments (file_get_contents, curl)

TacoV
  • 424
  • 1
  • 5
  • 17
  • 1
    Ok... I just read the comments saying exactly the same an hour ago >.<. Partially blind I guess. I'll leave the answer here so the answer isn't in the comments, but credits to Bart. – TacoV Sep 02 '15 at 07:56
0

Thanks to the comments above and the surprisingly helpful people at my WEB hosting company, I was able to write the following function:

function http_get($url)
{
    $ch = curl_init();    // initialize curl handle
    curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
    curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
    $result = curl_exec($ch); // run the whole process
    curl_close($ch); 
    return($result);
} //http_get

This works for many different URLs, but does fail on some servers, I hope by playing with the options I can get it working there.

Mike Higgins
  • 151
  • 5