Question

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.

Was it helpful?

Solution

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).

OTHER TIPS

Use curl instead?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top