在php中,我們經常會去抓取別的網站,而file_get_contents是其中一種常用的方式。但用file_get_contents抓取https的網站,會出錯,錯誤提示如下:
Warning: file_get_contents() [function.file-get-contents]: failed to open stream: Invalid argument in xxx.php on line xx
遇到這個問題不用慌,要解決file_get_contents無法抓取https協議的內容其實很簡單,只需打開php.ini文件找到 ;extension=php_openssl.dll ,去掉雙引號”;” ,重啟web服務器即可。如果是apache服務器的話,可以同時啟用mod_ssl模塊測試。
如果不方便修改服務器配置,可以使用curl來實現。
© 致遠 2020-01-18,原創內容,轉載請注明出錯:file_get_contents無法抓取https協議的內容的解決辦法