What potential security risks are involved in using file() to check webpage reachability in PHP?

Using file() to check webpage reachability in PHP can pose security risks as it allows for remote file inclusion, which can lead to arbitrary code execution on the server. To mitigate this risk, it is recommended to use cURL instead, which provides more control and security when making HTTP requests.

$url = 'https://www.example.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

if($response === false){
    echo 'Error reaching webpage';
} else {
    echo 'Webpage is reachable';
}

curl_close($ch);