Home  >  Article  >  Backend Development  >  php问题-PHP获取远程网页内容问题

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

WBOY
WBOYOriginal
2016-06-02 11:28:351328browse

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获取此网址均无法获取内容,导致服务器卡死,将上述网址替换为其他的网址,一切正常!!

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn