你好我主持我的网站到一个免费的托管网站(5gbfree.com),我在这里创建一个函数,它可以从网站http://ppa.com.ph??q=fcer_view那里检索比索美元的价格只需选择a.active
元素并以明文形式获取该值。它昨天正在工作,但当我今天早上再次检查它时,它未能取回。因此,这将返回默认值是50简单的HTML DOM - 无法打开流:连接超时
error_log中:
[09-Apr-2017 13:49:32 Asia/Manila] PHP Warning: file_get_contents(http://www.ppa.com.ph/?q=fcer_view): failed to open stream: Connection timed out in /home/rasibaseport/public_html/simple_html_dom2.php on line 75
我使用简单的HTML DOM。 这里有这个功能。
include "simple_html_dom2.php";
function PPA_peso_dollar_rate(){
// Create DOM from URL or file
error_reporting(E_ALL);
ini_set("display_errors", 0);
ini_set('default_socket_timeout', 15);
$html = file_get_html("http://www.ppa.com.ph/?q=fcer_view");
$ret = 0;
if($html === false){
$ret = 50;
}else {
foreach($html->find('a[class=active]') as $e)
$ret = $e->plaintext;
$explode = explode(" ", $ret);
$ret = 50;
foreach($explode as $ex){
if(is_numeric($ex)){
$ret = $ex;
}
}
if($ret == 0) $ret = 50;
}
echo $ret;
}
不幸的是5gbfree禁用了curl_init()函数。
curl_init() has been disabled for security reasons in /home/rasibaseport/public_html/config.php on line 38
这里有什么工作吗?我感谢任何帮助。非常感谢你。
编辑:我忘了提及用localhost(xampp)测试这个,期望的返回值是正确的,没有错误和警告。完美的工作。
更新:在尝试@ Rafiq的更新解决方案后,没有任何工作。它给了我类似的错误。
[09-Apr-2017 20:18:53 Asia/Manila] PHP Warning: file_get_contents(http://www.ppa.com.ph/?q=fcer_view): failed to open stream: Connection timed out in /home/rasibaseport/public_html/simple_html_dom2.php on line 46
太谢谢你了!你救了我的命。哈哈。你能解释一下,或者给我一个解释'ini_set('max_execution_time',秒)'的链接吗?只是有点好奇。无论如何,非常感谢你:) – legitghost
@ghost我加入回答 –
嗯,这很奇怪。我现在只是试了一下,而且没有再次工作。相同的错误日志error_log – legitghost