您可以张贴到检查数据库的第二个使用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 –