您可以張貼到檢查數據庫的第二個使用JavaScript半你每次和jQuery PHP頁面, 的JS將是(或包括在其中)的加載頁面:
var MyVar = ''; //whatever the default state is
window.setInterval(function(){
$.ajax({
url:"checkForOpponent.php",
dataType: 'text',
data: {state:MyVar},
success:function(data){
console.log('data loaded: ' + data); //just to check the console
if(data === "something i want"){
//Opponent state is good, change whatever you want
}else{
//Do the opposite
});
}, 500);
在你checkForOpponent.php你可以檢查$ _POST
if(isset($_POST['state'])){
//query database
//depending on returned result
echo 'something'; //this something will be read in your JS code above and act accordingly
}
AJAX或WebSockets是你解決這個問題的方法。 – Turrican
查找CRON作業。 –
你應該使用「cron」,這裏是一個鏈接http://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php –