先們來(lái)了解file_get_contents() 函數(shù),官方介紹說(shuō)它是把整個(gè)文件讀入一個(gè)字符串中,例子:
輸出:This is a test file with test text.同樣此函數(shù)還可以用于獲取遠(yuǎn)程服務(wù)器上的內(nèi)容:file_get_contents('http://www.phpfensi.com');這樣也是沒(méi)有問(wèn)題,但是如果我?guī)Я硕丝诹司陀袉?wèn)題了,例如:
file_get_contents('http://localhost:12345');
沒(méi)有任何獲取,解決方法是:關(guān)閉selinux
1,永久方法–需要重啟服務(wù)器
修改/etc/selinux/config文件中設(shè)置SELINUX=disabled ,然后重啟服務(wù)器。
2,臨時(shí)方法–設(shè)置系統(tǒng)參數(shù)
使用命令setenforce 0,附:
setenforce 1 設(shè)置SELinux 成為enforcing模式
setenforce 0 設(shè)置SELinux 成為permissive模式
php的allow_url_fopen選項(xiàng)是關(guān)閉了
原因是我們php.ini中把php的allow_url_fopen選項(xiàng)是關(guān)閉了,我們只要把它打開即可。