鍍金池/ 問答/PHP/ php file_get_contents() 與 curl函數(shù)

php file_get_contents() 與 curl函數(shù)

為什么file_get_contents()能遠程訪問站點?
我的理解:
file_get_contents()只是個文件函數(shù)呀!應(yīng)該不會有socket建立吧(雖然訪問也是遠程上的一個目錄/文件)
curl()能訪問是它幫我建立一個socket連接到訪問網(wǎng)站80。

比如:我網(wǎng)站的root目錄有一個test.php
file_get_contents('./test.php') & file_get_contents('127.0.0.1/test.php')兩者都是建立socket讀取輸入流的數(shù)據(jù)嗎?

回答
編輯回答
傲嬌范

對于file,file_get_content這類函數(shù),能不能打開url對象,是由allow_url_fopen這個參數(shù)決定的,高版本的php都是默認啟用的,默認使用http協(xié)議遠程訪問

2017年11月16日 09:06