>  기사  >  백엔드 개발  >  php问题-PHP获取远程网页内容问题

php问题-PHP获取远程网页内容问题

WBOY
WBOY원래의
2016-06-02 11:28:351330검색

php问题php

分别用了curl和file_get_contents均无法获取到内容,替换网址后就可以了,具体如下:

<code><?phpfunction getwebcontent($url){    $ch = curl_init();    $timeout = 10;    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);    curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);    $contents = trim(curl_exec($ch));    curl_close($ch);    return  $contents;} //$temps='http://127.0.0.1:50/admin/process_get.php?k=get&s=11&i=12367&url=www.100.com'; //$chS=file_get_contents($temps); $chS=getwebcontent('http://127.0.0.1:50/admin/process_get.php?k=get&s=11&i=12367&url=www.100.com'); echo $chS;?></code>

我的远程网址http://127.0.0.1:50/admin/process_get.php?k=get&s=11&i=12367&url=www.100.com 是可以访问的,内容为77788899

但通过curl和file_get_contents获取此网址均无法获取内容,导致服务器卡死,将上述网址替换为其他的网址,一切正常!!

老板说了,这个问题解决不掉,明天不让回家过年,请各位帮忙看看!!!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.