1、使用 file_get_contents() 函數(shù), 參數(shù)為域名地址時(shí)返回空,為ip地址時(shí)有數(shù)據(jù)。2、linux中可以ping 通 域名3、php-cli 執(zhí)行,可以訪問遠(yuǎn)程域名,并到得數(shù)據(jù)。4、通過瀏覽器 即php-fpm模式 curl 和 file_get_contents 都不可以訪問遠(yuǎn)程域名。5、在 /etc/hosts 中添加 220.181.112.244 www.baidu.com 后 php-fpm模式,就可以訪問到數(shù)據(jù)了。
代碼:
echo 1;
try {
var_dump(file_get_contents('http://220.181.112.244/index.html'));
// var_dump(file_get_contents('http://www.baidu.com'));
} catch (Exception $e) {
print_r($e->getTrace());
}
echo 2;
1、參數(shù)為:http://www.baidu.com
2、參數(shù)為:http://220.181.112.244/index....
3、在服務(wù)器執(zhí)行腳本,兩種參數(shù)都有返回?cái)?shù)據(jù)。
這是file_get_contents() 方法請(qǐng)求的錯(cuò)誤信息:
2018/05/26 22:16:03 [error] 24942#0: *46192 FastCGI sent in stderr: "PHP message: PHP Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /data/com.9b/duolaixue_admin/test_print/test.php on line 13
php curl 請(qǐng)求的錯(cuò)誤信息:Could not resolve host: www.baidu.com; Name or service not known
- 5 回答
- 0 關(guān)注
- 3757 瀏覽
添加回答
舉報(bào)
0/150
提交
取消