doumen9709
doumen9709
2017-01-24 10:23

PHP如何稍后设置内容或是否加载? [关闭]

  • delay
  • php
  • jquery

Hello I have a website which loads data from an api to show the newest stats. I am storing it for 10 minutes to prevent loading api calls every time. Since there are many api calls it takes at first time like 5-10 seconds to finish loading the website which looks like the website would be down.

Currently I am using pure php for functionalities. There are functions like GetTotalEarnings() - just a file_get_contents($url) to receive a json content and decode it and put it to a table which I can use for 10 minutes. After 10 minutes it will call all apis again to refresh the values (if the page get reloaded of course).

To solve this my idea was to load the content first and show the content and then load the data to set values later. But I don't know where to start. I know jquery can do this with a call back but its javascript. I don't know what tot do there

Two examples how looks currently

<h1 class=""><center>Earnings Total: <?php echo GetTotalEarnings() . " (Latest update: " . GetLatestUpdateTime() . ")"; ?></center></h1>


<h1 class="">This Month</h1>
<div class="col-xs-6 col-sm-6 col-md-3">
    <div class="box c1 center-block">
        <h4 class="blue">Today</h4>
        <span class="icon blue"><i class="fa fa-usd"></i></span>
        <span class="price-large blue"><?php echo round(GetTodayEarnings(), 2); ?></span>
    </div>
</div>
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐