我有一些代碼的PHP頁面轉換爲HTML:如何在同一臺服務器上使用php curl或file_get_content獲取url內容?
$dynamic = "http://website.net/home.php";
$out = "home.html" ;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"$dynamic");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$file = curl_exec($ch);
file_put_contents($out, $file);
這完美的作品在本地主機,但它需要太多的時間/不直播現場工作。我試過php_get_contents
,但這也行不通。
注:
http://website.net/home.php
頁面是在代碼託管在同一地點。curl
是啓用和allow_url_fopen
是在本地主機都在服務器按phpinfo()
。
編輯:
它使用其他網站的頁,而不是我的網站時,工作正常。
該網站的目標頁面完美載入我的瀏覽器。
我的網站的網頁加載速度快像往常一樣,但是當我用curl
或file_get_contents
,它的速度太慢,甚至無法得到輸出。
檢查你的服務器phpinfo()curl support = enabled和allow_url_fopen = on – 2014-09-19 09:59:16
確定主機/服務器上的'allow_url_fopen = on'? – davidkonrad 2014-09-19 10:01:31
curl已啓用且allow_url_fopen已啓用 – 2014-09-19 10:06:43