[function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
I am periodically getting this error, i.e it is only happening at random times, a
If the site requires basic authentication, you can give your credentials this way:
fopen("http://user:pass@www.example.com/path/to/resource", "r");
If it uses digest authentication, you'll have to handle it manually by reading the headers of the failed response and sending a new one with the correct headers. See HTTP context options for how to read and set headers and see how digest works in HTTP authentication with PHP.
You can also use the cURL extension or the HTTP PECL extension.