Clock update <?php echo microtime();?> Put into eho/msec.php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xcislav
Forum Newbie
Posts: 4
Joined: Fri Apr 11, 2014 9:00 am

Clock update <?php echo microtime();?> Put into eho/msec.php

Post by xcislav »

Now I need every time to press F5 <?php echo microtime(); ?>
But if I want to update the server clock every second what [setInterval] should i write?

Code: Select all

<script>
function update(){
    $('body').load('/eho.php');
}
update();
setInterval(function(){ update() }, 1000); 
</script>
I added to that code:
<?php echo microtime(); ?>
Changed places, files. I see no way how to make it work.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Clock update <?php echo microtime();?> Put into eho/msec

Post by Christopher »

If you want to make calls to the server every second (which sounds crazy) the use the jQuery ajax() function to make the calls.
(#10850)
xcislav
Forum Newbie
Posts: 4
Joined: Fri Apr 11, 2014 9:00 am

Re: Clock update <?php echo microtime();?> Put into eho/msec

Post by xcislav »

5+ seconds, not so crazy.

After apache+php+pdo setup there was a lot of not working things (themselves). And it works at last. I know jQuery is like something even more additional. And I read Ajax is for advanced javascript professionals.

So, it's a pity that it's completely out of the question to put into reality my try :(
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Clock update <?php echo microtime();?> Put into eho/msec

Post by Christopher »

It doesn't matter whether it is 1 second or 5 seconds. When I hear "update the server clock" it sounds like there is probably a better way to achieve your goal. Ajax is really not that difficult. jQuery makes it very easy. Ajax would be the preferred way to make calls to the server that are not initiated by a user action.

What is your goal when say "update the server clock" ?
(#10850)
xcislav
Forum Newbie
Posts: 4
Joined: Fri Apr 11, 2014 9:00 am

Re: Clock update <?php echo microtime();?> Put into eho/msec

Post by xcislav »

Ajax (pure JS no JQ).
Of three scripts that were given to me only one was working.
From it i took the unknown elements to internet search. But lots of water and queries (that take away).

Code: Select all

window.XMLHttpRequest
new XMLHttpRequest()(
"
Microsoft.XMLHTTP
")
if !== null && undefined
onreadystatechange = function() { if(
readyState == 4
document.body.innerHTML
.respondeText
.open("GET", "/eho.php", true)
;
.send(null);
window.onload
setInterval
Post Reply