我有一個文件打開一個URL並讀取它並進行解析。 現在,如果該URL去dwon,我的文件無法打開它,那麼我需要的是一個錯誤郵件應該生成,但終端或konsole應該出現錯誤信息。 我該怎麼做? Plz help !!php中的錯誤處理
1
A
回答
2
你總是可以做這樣的事情(我假設你正在使用的file_get_contents)
$file = @fopen("abc.com","rb");
if(!$file) {
@mail(.......);
die();
}
//rest of code. Else is not needed since script will die if hit if condition
0
if (!$content = file_get_contents('http://example.org')) {
mail(...);
}
1
使用捲曲,而不是如果你在網絡上檢索文件。它內置了錯誤處理,它會告訴你發生的錯誤。使用file_get_contents不會告訴你哪裏出了問題,它也不會遵循重定向。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://domain.com/file');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$result = curl_exec($ch);
if ($result == false) {
$errorInfo = curl_errno($ch).' '.curl_error($ch);
mail(...)
} else {
//Process file, $result contains file contents
}
相關問題
- 1. 在PHP中處理錯誤
- 2. 在PHP中處理錯誤
- 3. 在PHP中處理錯誤
- 4. PHP處理錯誤
- 5. PHP錯誤處理
- 6. PHP - 錯誤處理
- 7. PHP錯誤處理
- 8. datepicker php的錯誤處理
- 9. PHP的URL錯誤處理
- 10. SimpleXML的錯誤處理PHP
- 11. PHP的錯誤處理
- 12. php symfony異常處理/錯誤處理
- 13. PHP錯誤處理和異常處理?
- 14. 如何處理PHP中的db2_fetch_assoc錯誤?
- 15. 在php中未處理的錯誤
- 16. PHP類中的錯誤處理
- 17. PHP中的數據庫錯誤處理
- 18. PHP中的對象和錯誤處理
- 19. 處理Python異常/ PHP中的錯誤
- 20. PHP foreach函數中的錯誤處理
- 21. 錯誤處理PHP函數
- 22. MySQL和PHP錯誤處理
- 23. jquery parseJSON處理php錯誤
- 24. 錯誤處理PHP類
- 25. PHP MVC MySQL錯誤處理
- 26. PHP MySQL錯誤處理
- 27. json_encode錯誤處理PHP OOP
- 28. PHP AJAX錯誤處理
- 29. PHP simplexml_load_file - 錯誤處理
- 30. PHP類錯誤處理
這就是使用何種即時通訊做,即時通訊@fopen代替@file_get_contents,但我想要的是使用這種代碼的IM,當我執行終端上得到錯誤信息在終端/ Konsole.By應該NOE出現的錯誤它在那裏。我希望沒有錯誤消息出現在termianl上。 – developer 2009-05-21 13:11:22