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.
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