views:

320

answers:

3

I've got a simple php script to ping some of my domains using file_get_contents(), however I have checked my logs and they are not recording any get requests.

I have

$result = file_get_contents($url);
echo $url. ' pinged ok\n';

where $url for each of the domains is just a simple string of the form http://mydomain.com/, echo verifies this. Manual requests made by myself are showing.

Why would the get requests not be showing in my logs?

Actually I've got it to register the hit when I send $result to the browser. I guess this means the webserver only records browser requests? Is there any way to mimic such in php?

ok tried curl php:

// create curl resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, "getcorporate.co.nr");

//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// $output contains the output string
$output = curl_exec($ch);

// close curl resource to free up system resources
curl_close($ch);

same effect though - no hit registered in logs. So far it only registers when I feed the http response back from my script to the browser. Obviously this will only work for a single request and not a bunch as is the purpose of my script.

If something else is going wrong, what debugging output can I look at?

Edit: D'oh! See comments below accepted answer for explanation of my erroneous thinking.

A: 

Use curl instead?

Azeem.Butt
tried it, same effect. see expansion in original post
rutherford
A: 

That's odd. Maybe there is some caching afoot? Have you tried changing the URL dynamically ($url = $url."?timestamp=".time() for example)?

Pekka
No def not. Tried the timestamp to make sure.
rutherford
+2  A: 

If the request is actually being made, it would be in the logs.

Your example code could be failing silently.

What happens if you do:

<?PHP
if ($result = file_get_contents($url)){
    echo "Success"; 
}else{
    echo "Epic Fail!";
}

If that's failing, you'll want to turn on some error reporting or logging and try to figure out why.

Note: if you're in safe mode, or otherwise have fopen url wrappers disabled, file_get_contents() will not grab a remote page. This is the most likely reason things would be failing (assuming there's not a typo in the contents of $url).

timdev
I did an echo on a single file_get_contents($url) request and while obviously returning the entire contents of the request to my browser it was also recorded on the server. So the call to file_get_contents() is working
rutherford
And you say that if your script echos the response to a browser, you get something in the remote server log? If you're 100% sure that's right, then I have no idea. If you make a very simple case, a script that just does file_get_contents($url), does that not create a log entry? And when you change it to "echo file_get_contents($url);" the log entries start showing up?
timdev
balls. My request goes to a html file that includes frames. It's one of the frame pages that I'm checking the logs of. So I'm guessing a simple http request obviously doesn't chase all included frames the way a browser does automatically. I'm sure this is a candidate for one of those loser type badges.
rutherford
Exactly right. But there should be an entry in the log for the GET of the page that contains your frames. I'm guessing that you were looking for log entries for some other page.
timdev
no doubt it has but it's on another domain out of my control. Thanks again for nudging me in the right direction
rutherford