我試圖做腳本,檢查站點是否啓動或關閉。一切工作正常,但當網站不是一個網站,我的意思是該網站不存在。然後php執行加載時間增加。我想以某種方式處理這個問題。如何檢查網站是否存在並打破捲曲會話?這裏是我的腳本:PHP:如何處理捲曲響應
<?php
$ch = curl_init('http://86.100.69.228/'); // e.g. for this will increase execution time because the site doesn't exists
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo $status_code;
curl_close($ch);
?>