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

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

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

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

回答
編輯回答
傲嬌范

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

2017年11月16日 09:06