▇►–• สอบถาม เกี่ยวกับ function get_content หน่อยครับผม

เริ่มโดย beemank, 14 มีนาคม 2011, 23:06:12

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

beemank

คือผมมีปัญหาอยู่ว่า ผมใช้

function get_content($filename){
if(function_exists('file_get_contents')){
$html = file_get_contents($filename);
}else{
$handle = fopen($filename, "r");
$html = fread($handle, filesize($filename));
fclose($handle);
}
return $html;
}


แล้วเวลามันสร้างหน้า html มันชอบขึ้นว่า

Warning: file_get_contents(http://ปปป.com/templates/noma/index.html) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /home/ปปป/domains/ปปป.com/public_html/include/ปปป.php on line 41

หลายหน้าเลยอ่ะครับ เคยใ้ช้ที่ panel ของ cpanel ไม่ค่อยเป็นครับ แต่พอย้ายมาลงกับ panel ที่เป็น Direct Admin มันเป็นบ่อยมากครับ จะขึ้นมาวันเป็น พันหน้าเลยครับ ไม่ทราบว่าพอจะมีวิธีแก้ไขป่ะครับ

ขอบคุณครับ :wanwan017:

thongtae

ลองเช็คฟังก์ชัน file_get_contents() หรือยังครับ ดูเหมือนว่ามันติดลูปอยู่ :wanwan015:

beemank

อ้างถึงจาก: thongtae ใน 14 มีนาคม 2011, 23:35:11
ลองเช็คฟังก์ชัน file_get_contents() หรือยังครับ ดูเหมือนว่ามันติดลูปอยู่ :wanwan015:

เช็คไงเหรอครับ พอดีผมไม่ค่อยรู้เรื่องอ่ะครับ แนะนำหน่อยได้ป่ะครับ ขอบคุณครับ

thongtae

จากERRORข้างต้น ตรงคำว่า [function.file-get-contents]: failed to open stream ชื่อฟังก์ชันใช้ถูกหรือพิมพ์ผิดหรือเปล่า
ใช้WP หรือเขียนPHPเองครับ

beemank

php เขียนเองครับผม แต่จริงๆคือมันก็ยังสร้างหน้า page ได้นะครับ แต่ว่ามันจะเกิดปัญหาข้างต้นบ่อยมากอ่ะครับผม

beemank


xvlnw.com

จะดึงหน้าเว็บมาใช่มะครับ ผมแนะนำ CURL ครับ
[direct=https://cloudhost.in.th/wordpress-hosting]ツ ⓌⓄⓇⒹⓅⓇⒺⓈⓈ ⒽⓄⓈⓉⒾⓃⒼ [/direct] :wanwan014:  :D
[direct=https://cloudhost.in.th/cloudhosting.html]Cloud Hosting[/direct] [direct=https://cloudhost.in.th/cloudvps.html]Cloud Server[/direct] [direct=https://cloudhost.in.th/vpshosting.html]Cloud VPS Hosting[/direct] [direct=https://cloudhost.in.th/windowsvps.html]Cloud Windows[/direct] Tel: 080-348-0843 LINE: ixvlnw

beemank

ผมต้องแก้เป็นยังไงอ่ะครับ รบกวนหน่อยครับ  :wanwan017:

pugkung

ลองเช็ค url ที่ใช้ดึงเพจนี้ดูครับว่าใส่อะไรเกินหรือขาดไปหรือปล่าว

mean

file_get_contents ช้ากว่า curl มากครับ

จำได้เคยแปะ code ไปหลายทีแล้ว ลอง ขุดดูนะครับ น่าจะนำมาปรับใช้ได้ไม่ยาก
http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl
http://www.google.co.th/search?q=curl+get+content&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
http://davidwalsh.name/execute-http-post-php-curl


[direct=https://www.ireallyhost.com/]บริการโดเมน, เว็บโฮสติ้ง, SSL Certificate[/direct]
[direct=https://www.ireallyhost.com/ssl]บริการ SSL Certificate , HTTPS สำหรับเว็บไซต์[/direct]
[direct=https://www.ireallyhost.com/]บริการ Web Hosting Free! Domain name ตลอดอายุบริการ [/direct]
[direct=https://www.ireallyhost.com/domain]บริการ จดโดเมน, Free DNS Service, Domain Forwarding, จัดการโดเมนได้เอง Domain Control Panel[/direct

mean

ขอตอบที่นี่จะได้ มีประโยชน์ กับผู้อื่นต่อไปครับ
ลองมั่ว ลองดู ลองหา ดู manual ให้เป็น จะพัฒนาไปได้เร็วครับ
http://th2.php.net

อ้างถึงจาก: beemank ใน 15 มีนาคม 2011, 14:51:39
พี่ึครับ จากกระทู้ http://www.thaiseoboard.com/index.php/topic,180693.msg2463502/topicseen.html#new
ถ้ารบกวนพี่แก้ให้หน่อยได้ป่ะครับเพราะว่าผมแก้ไม่เป็นอ่ะครับ พอดีเพิ่งหัดแล้วตัวสคริป ก็ซื้อมาอ่ะครับ ถ้าพี่พอมีเวลา หรือถ้ามีค่าใช้จ่ายยังไงก็บอกได้ครับผม พอดีกลัวแก้แล้วไปหมดอ่ะครับ :wanwan017:

function get_content($filename){
if(extension_loaded('curl')){
    $ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $filename);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$html = curl_exec ($ch);
}
else if(function_exists('file_get_contents')){
$html = file_get_contents($filename);
}else{
$handle = fopen($filename, "r");
$html = fread($handle, filesize($filename));
fclose($handle);
}
return $html;
}


เพิ่มเติม ผู้ให้บริการโฮสติ้ง เจ้าของเซิร์ฟเวอร์ อาจมีการเช็ค connection ไว้ครับ
ลองแก้โดยวิธี ใส่ ฟังก์ชั่น delay อย่าง sleep หรือ usleep ไปหน่วง แต่การ call function ดูครับ


[direct=https://www.ireallyhost.com/]บริการโดเมน, เว็บโฮสติ้ง, SSL Certificate[/direct]
[direct=https://www.ireallyhost.com/ssl]บริการ SSL Certificate , HTTPS สำหรับเว็บไซต์[/direct]
[direct=https://www.ireallyhost.com/]บริการ Web Hosting Free! Domain name ตลอดอายุบริการ [/direct]
[direct=https://www.ireallyhost.com/domain]บริการ จดโดเมน, Free DNS Service, Domain Forwarding, จัดการโดเมนได้เอง Domain Control Panel[/direct

beemank

อ้างถึงจาก: mean ใน 15 มีนาคม 2011, 15:34:53
ขอตอบที่นี่จะได้ มีประโยชน์ กับผู้อื่นต่อไปครับ
ลองมั่ว ลองดู ลองหา ดู manual ให้เป็น จะพัฒนาไปได้เร็วครับ
http://th2.php.net

อ้างถึงจาก: beemank ใน 15 มีนาคม 2011, 14:51:39
พี่ึครับ จากกระทู้ http://www.thaiseoboard.com/index.php/topic,180693.msg2463502/topicseen.html#new
ถ้ารบกวนพี่แก้ให้หน่อยได้ป่ะครับเพราะว่าผมแก้ไม่เป็นอ่ะครับ พอดีเพิ่งหัดแล้วตัวสคริป ก็ซื้อมาอ่ะครับ ถ้าพี่พอมีเวลา หรือถ้ามีค่าใช้จ่ายยังไงก็บอกได้ครับผม พอดีกลัวแก้แล้วไปหมดอ่ะครับ :wanwan017:

function get_content($filename){
if(extension_loaded('curl')){
    $ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $filename);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$html = curl_exec ($ch);
}
else if(function_exists('file_get_contents')){
$html = file_get_contents($filename);
}else{
$handle = fopen($filename, "r");
$html = fread($handle, filesize($filename));
fclose($handle);
}
return $html;
}


ตัวนี้เอาไปแทนตัว

function get_content($filename){
if(function_exists('file_get_contents')){
$html = file_get_contents($filename);
}else{
$handle = fopen($filename, "r");
$html = fread($handle, filesize($filename));
fclose($handle);
}
return $html;
}

ได้เลยใช่ป่ะครับ ขอบคุณมากคับ

beemank

พี่ mean ครับ error เดิมหายแล้วครับแต่มันจะเป็น error 404 แทนอ่ะครับ  :wanwan017: