股票行情使网站负载超长


Stock ticker makes site load extremely long

我需要用specchips股票构建一个股票行情器,经过很长时间的搜索,我找到了Simple PHP股票行情器和Javascript Marquee,用于有效的XHTML whic,经过一些调整,找到了正确的.htaccess文件和我所能使其工作的所有文件,当它本身是一个单独的html文件时,它或多或少是可以的,但当我将它添加到joomla时,带有ticker的页面需要非常长的时间才能加载,我还没有添加"stockcache"目录,所以它实际上没有加载任何内容,但仍然需要很长时间才能加载。

这是代码(独立的html文件)

<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>stockticker</title>
<!--    <link rel="stylesheet" href="stockticker.css"> -->
<style type="text/css"> 
#marqueeborder {
color: #cccccc;
font-family:"Verdana", Monaco, monospace;
position:relative;
height:20px; 
overflow:hidden;
font-weight:bold;
font-size: 0.7em;
}
#marqueecontent {
position:absolute;
left:0px;
line-height:20px;
white-space:nowrap;
}
.stockbox {
margin:0 10px;
color: #000044;
}
.stockboxname {
color: #359ad2;
}
</style>
<script type="text/javascript">
    // Original script by Walter Heitman Jr, first published on     http://techblog.shanock.com
    // Set an initial scroll speed. This equates to the number of pixels shifted per         tick
var scrollspeed=3;
var pxptick=scrollspeed;
function startmarquee(){
    // Make a shortcut referencing our div with the content we want to scroll
    marqueediv=document.getElementById("marqueecontent");
    // Get the total width of our available scroll area
    marqueewidth=document.getElementById("marqueeborder").offsetWidth;
    // Get the width of the content we want to scroll
    contentwidth=marqueediv.offsetWidth;
    // Start the ticker at 50 milliseconds per tick, adjust this to suit your      preferences
    // Be warned, setting this lower has heavy impact on client-side CPU usage.     Be gentle.
    setInterval("scrollmarquee()",50);
    }
function scrollmarquee(){
    // Check position of the div, then shift it left by the set amount of     pixels.
        if (parseInt(marqueediv.style.left)>(contentwidth*(-1)))
        marqueediv.style.left=parseInt(marqueediv.style.left)-pxptick+"px";
        // If it's at the end, move it back to the right.
    else
            marqueediv.style.left=parseInt(marqueewidth)+"px";
    }
    window.onload=startmarquee;
</script>
</head>

<body>

<div id="marqueeborder" onmouseover="pxptick=0" onmouseout="pxptick=scrollspeed">
<div id="marqueecontent">
<?
    // Original script by Walter Heitman Jr, first published on     http://techblog.shanock.com
    // List your stocks here, separated by commas, no spaces, in the order you want them     displayed:
    $stocks = "<!--stocks--    >KO,FB,AAPL,JPM,MSFT,GOOG,TWTR,VOD,SCGLF,VXX,SBRCY,SSNLF,IBN,WEBNF,<!--comodeties--    >GCV14.CMX<!--gold-->,SIZ13.CMX<!--silver-->,PLF14.NYM<!--platinum-->,CZ13.CBT<!--corn--    >,KCZ13.NYB<!--cofee-->,SBH14.NYB<!--sugar-->";
    // Function to copy a stock quote CSV from Yahoo to the local cache. CSV contains     symbol, price, and change
    function upsfile($stock) { copy("http://finance.yahoo.com/d/quotes.csv?    s=$stock&f=sl1c1&e=.csv","stockcache/".$stock.".csv"); }
    foreach ( explode(",", $stocks) as $stock ) {
        // Where the stock quote info file should be...
    $local_file = "stockcache/".$stock.".csv";
    // ...if it exists. If not, download it.
    if (!file_exists($local_file)) { upsfile($stock); }
    // Else,If it's out-of-date by 15 mins (900 seconds) or more, update it.
    elseif (filemtime($local_file) <= (time() - 900)) { upsfile($stock); }
    // Open the file, load our values into an array...
    $local_file = fopen ("stockcache/".$stock.".csv","r");
    $stock_info = fgetcsv ($local_file, 1000, ",");
    // ...format, and output them. I made the symbols into links to Yahoo's stock pages.
    echo "<span class='"stockbox'"><span class='"stockboxname'">".$stock_info[0]."</span> ".sprintf("%.2f",$stock_info[1])." <span style='"";
    // Green prices for up, red for down
    if ($stock_info[2]>=0) { echo "color: #009900;'">&uarr;";   }
    elseif ($stock_info[2]<0) { echo "color: #ff0000;'">&darr;"; }
    echo sprintf("%.2f",abs($stock_info[2]))."</span></span>'n";
    // Done!
    fclose($local_file); 
}
?>
<!--
<span class="stockbox" style="font-size:0.6em">Quotes from <a     href="http://finance.yahoo.com/">Yahoo Finance</a></span>
-->
</div>
</div>
</body>

我把脚本放在header.php中,把php放在一篇文章

这行有点乱:

$stocks = "<!--stocks--    >KO,FB,AAPL,JPM,MSFT,GOOG,TWTR,VOD,SCGLF,VXX,SBRCY,SSNLF,IBN,WEBNF,<!--comodeties--    >GCV14.CMX<!--gold-->,SIZ13.CMX<!--silver-->,PLF14.NYM<!--platinum-->,CZ13.CBT<!--corn--    >,KCZ13.NYB<!--cofee-->,SBH14.NYB<!--sugar-->";

你需要拿出评论并将其更改为:

$stocks = "KO,FB,AAPL,JPM,MSFT,GOOG,TWTR,VOD,SCGLF,VXX,SBRCY,SSNLF,IBN,WEBNF,GCV14.CMX,SIZ13.CMX,PLF14.NYM,CZ13.CBT,KCZ13.NYB,SBH14.NYB";

否则,您的代码将尝试拉取,例如:

"<!--stocks--    >KO" 

作为雅虎金融的第一个股票报价,同样也引发了黄金、白银、铂金、玉米、咖啡和糖报价的问题。PHP没有

<!-- 

像HTML一样使用样式引用。它使用/**/样式的引号。

在你做到这一点之后,它可能会更快地工作,因为雅虎不必花那么多时间试图弄清楚你到底想从他们那里得到什么。