php需要很长时间才能显示结果

时间:2014-01-16 04:07:15

标签: php

我有这个代码并且它正常工作唯一的问题是它需要花费一个半小时从外部页面返回值,我不太确定是什么导致问题我的意思是它正常工作所以它显然不是一个编码问题,至少没有我认为,任何帮助将不胜感激

<?php
echo "<style type='text/css'>
html{color:#fff;
font-weight:bold;
}
.btn{
background: url(/runescape/navbar.gif);

border:solid 1px #fff;
color:#fff;

}
.addbar{
background:#333;
color:#fff;

}</style>";

$username = $_REQUEST['lookup'];

$hs = file_get_contents("http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=".$username);

$hs = explode("\n",$hs);

$skills = array("overall","attack","def","str","hp","range","prayer","magic","cook","wc","fletch","fishing","firemaking","crafting","smithing","mining","herb","agility","steal","slayer","farming","runecrafting","hunter","cons");

$i = 0;



foreach($skills as $value){

$hs[$i] = explode(",",$hs[$i]);



$stats[$value]["level"] = $hs[$i][1];



$i++;
}

echo "<center>";
echo " <form action='/runescape/phpfile/hs.php'>";
echo "<input class='addbar' name='lookup' id='lookup' type='text' />";
echo "<input class='btn' name='submit' type='submit' value='submit' /></form> ";

echo $stats["attack"]["level"];






 ?>
使用curl添加此脚本

修复了

问题

    function curl_file_get_contents($url)
    {
     $curl = curl_init();
     $userAgent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';

     curl_setopt($curl,CURLOPT_URL,$url); //The URL to fetch. This can also be set when initializing a session with curl_init().
     curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE); //TRUE to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly.
     curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,5); //The number of seconds to wait while trying to connect.  

     curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); //The contents of the "User-Agent: " header to be used in a HTTP request.
     curl_setopt($curl, CURLOPT_FAILONERROR, TRUE); //To fail silently if the HTTP code returned is greater than or equal to 400.
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); //To follow any "Location: " header that the server sends as part of the HTTP header.
     curl_setopt($curl, CURLOPT_AUTOREFERER, TRUE); //To automatically set the Referer: field in requests where it follows a Location: redirect.
     curl_setopt($curl, CURLOPT_TIMEOUT, 10); //The maximum number of seconds to allow cURL functions to execute.   

     $contents = curl_exec($curl);
     curl_close($curl);
     return $contents;
    }

并改变了这一点     $ hs = file_get_contents(“http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=”。$ username);

要    $ hs = curl_file_get_contents(“http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player=”。$ username);

0 个答案:

没有答案