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;
}
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.