使用PHP获取其他类型的远程URL内容有哪些?

时间:2012-10-16 20:44:17

标签: php curl file-get-contents fread fsockopen

在PHP中是否有其他类型的获取远程数据,除了:"cURL"并且 php.ini 中的"allow_url_fopen"设置为"On",能够使用"fopen""fsockopen""file_get_contents"流式传输远程内容吗?

我正在开发自定义PHP远程内容流媒体,如果"cURL""allow_url_fopen""Off",我正在寻找其他任何流式传输远程内容的方式。< / p>

2 个答案:

答案 0 :(得分:1)

运行系统调用怎么样?与passthru()exec()system()一样,并在命令行上调用curlwget并捕获数据

Linux示例:

ob_start();
passthru("wget -U 'CustomUserAgent' -q -O - 'http://www.example.com/'");
$output = ob_get_clean();

Windows 7+示例(通过powershell)。取自here

(new-object System.Net.WebClient).DownloadFile('http://www.example.come','C:\tmp\output.tx‌​t') –

要展开Windows方法,请参阅executing a Powershell script from php

答案 1 :(得分:1)

“allow_url_fopen”不会影响“fsockopen”。

即使这样做,在网络服务器中启用系统调用也是比“allow_url_fopen = On”更大的安全威胁。

要禁用fsockopen,可将其添加到php.ini中的“disable_functions”