How would I add a loop to this PHP coding? I want to make it so that after ‘I AM THOMAS’ it will loopback to ‘HELLO WORLD’ and repeat the same cycle infinitely.
How do I make a loop for PHP? Is this right?
<?PHP
require (“config.php”);
exec(“mode com3: BAUD=9600 PARITY=n DATA=8 STOP=1 to=off dtr=off rts=off”);
$fp =fopen(“com3”, “w”);
while (true){
fwrite($fp,“HELLO WORLD”);
fwrite($fp,“I AM THOMAS”);
sleep(5);
}
fclose($fp);
?>
You could wrap it with a while true loop but, the trouble is that php scripts are designed to time out after a certain period of time.
So instead, you could remove the sleep command, and tell the HTML page to reload it self using a meta refresh command.
<meta http-equiv="refresh" content="5">
paul_wilkins:
You could wrap it with a while true loop but, the trouble is that php scripts are designed to time out after a certain period of time.
So instead, you could remove the sleep command, and tell the HTML page to reload it self using a meta refresh command.
<meta http-equiv="refresh" content="5">
hm, that is just refreshing the page every 5 seconds. how do i get the page to run from the background rather than clicking it to execute? because this will be attaching to another file via <a href=mypage.php>
You can use either the client or the server.
With the client, the meta refresh is a good solution.
If you want your server to constantly refresh something, that is where you could use a cron job instead.
I’m not aware of any other other useful ways to achieve it.