user2736113
user2736113

Reputation: 9

How i can execute a code every one minute in php?

I wanna update my database when users visiting my site , every one minute, I use this code :

 $stmt = $dbConnection->prepare( "UPDATE db1_etchat_user SET alaghe=? WHERE etchat_username=?");    
$stmt->execute(array($alaghe,$username));

I wanna every one minute that's user visit my site , my columns be updated.

Excuse me for my bad English.

Upvotes: 0

Views: 170

Answers (3)

MD SHAHIDUL ISLAM
MD SHAHIDUL ISLAM

Reputation: 14523

page2.php will call after every 1 minute

page1.php

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" 
type="text/javascript"></script>
<script>
function doUpdate() {
    $.ajax({
        url:"page2.php",
        success: function(resp) {
           setTimeout(doUpdate, 1000*60); //1000 = 1 minute
        }
    });
}
 setTimeout (   doUpdate, 1000*60 );
</script>

page2.php

$stmt = $dbConnection->prepare( "UPDATE db1_etchat_user SET alaghe=? 
                                                  WHERE etchat_username=?");    
$stmt->execute(array($alaghe,$username));

Upvotes: 0

bish
bish

Reputation: 3419

You could use a cronjob and start the php-file you want to execute.

Upvotes: 0

Alex
Alex

Reputation: 1593

Make Ajax request to your server once per minute.

Upvotes: 1

Related Questions