0

As part of automating a web-shop, will 300+ get_headers(); requests affect the target servers? I realize I only request the headers without the content, but it's still an HTTP request.

To quickly break the code down; 300+ urls are sequentially passed onto the function, which then checks the headers, searching for '404'.

I don't want to unnecessarily stress someone else's server.

The code I have set up is as following:

function checkUrlExists($url) {
    stream_context_set_default(
        array(
            'http' => array(
                'method' => 'HEAD'
            )
        )
    );
    $headers = @get_headers($url);
    if (is_array($headers)) {
        if (strpos($headers[0], '404') === false)
            return true;
        else
            return false;
    } else
        return false;
}
Matthijs
  • 51
  • 6

1 Answers1

1

It will in most cases stress is as much as doing the full request. Unless the application is specifically built to handle HEAD requests in a different way, it will bootstrap the code, run it and then retrieve only the headers. From the application's perspective, there is no difference, only from the webserver's perspective.

wimg
  • 347
  • 1
  • 8
  • Thank you, I will fit in a sleep() then to reduce the stress. Execution time doesn't matter anyway, as it'll go to cron. – Matthijs Feb 25 '15 at 15:59