duancenxie2233 2015-08-31 15:35
浏览 16
已采纳

重复网站中包含的PHP脚本

I've searched all around for a solution to my problem, but I can't seem to understand where to put the solution.

I'm creating a webpage which will show information from different API sources, and I would like all the information to be updated on different intervals.

I've seen the "while(true) { sleep(5); }" solution, but it just freezes the website, preventing it to load.

Lets say my webpage looks like this:

<body>
<?php

echo "hello world";

?>
</body>

How can I make the php script repeat on certain intervals?

Thank you.

  • 写回答

1条回答 默认 最新

  • douyu2817 2015-08-31 16:09
    关注

    The question you have is basically about the use of client side and server side scripting. A language like php runs on the server and not on the computer of the client, the user. Therefore, it cannot change anything on the webpage as soon as it has been sent off to the user. That is where client-side scripts come in play.

    The server can send a script in a language like javascript to the user if a link to the script is included in the html. Those scripts will be executed on the user's browser. With an combination of Javascript and AJAX (stands for Asynchronous JavaScript and XML, and is not a language btw), you can load a php-file into your page. You can use javascript to let AJAX do that every x miliseconds with the function setInterval()

    A few links and tutorials:

    http://www.w3schools.com/ajax/

    http://www.w3schools.com/jsref/met_win_setinterval.asp

    http://www.w3schools.com/js/default.asp

    http://www.tutorialspoint.com/ajax/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改