Are there potential pitfalls in using the system function in PHP to check webpage availability?

Using the system function in PHP to check webpage availability can introduce security risks as it allows the execution of arbitrary commands on the server. To mitigate this risk, it is recommended to use alternative methods such as cURL or file_get_contents to check webpage availability in a safer manner.

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

if ($response === false) {
    echo 'Webpage is not available';
} else {
    echo 'Webpage is available';
}

curl_close($handle);