The best I could find, an if
fclose
fopen
type thing, makes the page load really slowly.
Basically what I\'m trying to do is
If you're using the Symfony framework, there is also a much simpler way using the HttpClientInterface
:
private function remoteFileExists(string $url, HttpClientInterface $client): bool {
$response = $client->request(
'GET',
$url //e.g. http://example.com/file.txt
);
return $response->getStatusCode() == 200;
}
The docs for the HttpClient are also very good and maybe worth looking into if you need a more specific approach: https://symfony.com/doc/current/http_client.html