我正在开发一个彩票网站,但遇到了一个问题。所以请帮帮我。我在这里解释一下情况:这是彩票页面http://studysesh.org/greenstreak/mark/lottery1.php的链接。彩票页面有3个不同时间结果的彩票。例如,每6小时后第一次抽奖结果,24小时后结果为第2次,7天后结果为第3次结果。我编写了PHP中的所有功能。当站点在任何浏览器中打开时,它会在每秒使用Ajax请求检查彩票结果。但是,我的问题是,如果我关闭浏览器,它将不会检查任何值。我使用了一分钟的cron作业来代码:
$select = mysql_query("Select * from tbl_rooms where room_status='1'");
$countRows = mysql_num_rows($select);
if($countRows>0)
{
while($rows = mysql_fetch_assoc($select))
{
$date1 = date("Y-m-d H:i:s");
$date2 = $rows['room_end_date'];
$date1Timestamp = strtotime($date1);
$date2Timestamp = strtotime($date2);
if($date1 < $date2){
//convert the date back to underscore format if needed when printing it out.
// echo '1 is small='.$date1.','.date('d_m_y',$date1);
//Calculate the difference.
$difference = $date2Timestamp - $date1Timestamp;
//echo $difference;
if($difference < 60)
{
sleep($difference);
$room_title=$rows['room_title'];
$room_id=$rows['room_id'];
if($room_title == 'Quick Six')
{
$update_date= date('Y-m-d H:i:s', strtotime('6 hour'));
mysql_query("UPDATE `tbl_rooms` SET `room_end_date`='$update_date' WHERE `room_title`='Quick Six'");
}
if($room_title == 'Daily Draw')
{
$update_date= date('Y-m-d H:i:s', strtotime('24 hour'));
mysql_query("UPDATE `tbl_rooms` SET `room_end_date`='$update_date' WHERE `room_title`='Daily Draw'");
}
if($room_title == 'Lucky Seven')
{
$update_date= date('Y-m-d H:i:s', strtotime('7 day'));
mysql_query("UPDATE `tbl_rooms` SET `room_end_date`='$update_date' WHERE `room_title`='Lucky Seven'");
}
$buyroom_query=mysql_query("SELECT distinct `u_id` FROM `tbl_buyroom` where `room_id`='$room_id'");
$buyroom_count=mysql_num_rows($buyroom_query);
if($buyroom_count >= 5)
{
$room_coin=round($rows['room_price']*0.65);
$winner_query=mysql_query("SELECT distinct `u_id` FROM `tbl_buyroom` where `room_id`='$room_id' ORDER BY RAND() LIMIT 5 ;");
$i=0;
while($winner_id=mysql_fetch_assoc($winner_query))
{
$i++;
$user_id=$winner_id['u_id'];
$a[]=$winner_id['u_id'];
$user_query=mysql_query("SELECT * FROM `tbl_users` where `id`='$user_id'");
$result_query=mysql_fetch_assoc($user_query);
$price=$result_query['total_coin'];
if($i==1)
{
$win_id1=$user_id;
$user_coin=0;
$user_coin=round($room_coin*0.50);
$win_coin=$price+$user_coin;
mysql_query("UPDATE `tbl_users` SET `total_coin`='$win_coin' WHERE id='$user_id'");
mysql_query("INSERT INTO `tbl_rooms_win`(`room_id`, `u_id`, `win_date`, `price`, `win_status`) VALUES ('$room_id','$user_id','$date1','$user_coin','1')");
success_mail($user_id, $room_title, $user_coin, $win_coin);
$win[]=$win_coin;
}
if($i==2)
{
$win_id2=$user_id;
$user_coin=0;
$user_coin=round($room_coin*0.25);
$win_coin=$price+$user_coin;
mysql_query("UPDATE `tbl_users` SET `total_coin`='$win_coin' WHERE id='$user_id'");
mysql_query("INSERT INTO `tbl_rooms_win`(`room_id`, `u_id`, `win_date`, `price`, `win_status`) VALUES ('$room_id','$user_id','$date1','$user_coin','1')");
success_mail($user_id, $room_title, $user_coin, $win_coin);
$win[]=$win_coin;
}
if($i==3)
{
$win_id3=$user_id;
$user_coin=0;
$user_coin=round($room_coin*0.13);
$win_coin=$price+$user_coin;
mysql_query("UPDATE `tbl_users` SET `total_coin`='$win_coin' WHERE id='$user_id'");
mysql_query("INSERT INTO `tbl_rooms_win`(`room_id`, `u_id`, `win_date`, `price`, `win_status`) VALUES ('$room_id','$user_id','$date1','$user_coin','1')");
success_mail($user_id, $room_title, $user_coin, $win_coin);
$win[]=$win_coin;
}
if($i==4)
{
$win_id4=$user_id;
$user_coin=0;
$user_coin=round($room_coin*0.06);
$win_coin=$price+$user_coin;
mysql_query("UPDATE `tbl_users` SET `total_coin`='$win_coin' WHERE id='$user_id'");
mysql_query("INSERT INTO `tbl_rooms_win`(`room_id`, `u_id`, `win_date`, `price`, `win_status`) VALUES ('$room_id','$user_id','$date1','$user_coin','1')");
success_mail($user_id, $room_title, $user_coin, $win_coin);
$win[]=$win_coin;
}
if($i==5)
{
$win_id5=$user_id;
$user_coin=0;
$user_coin=round($room_coin*0.06);
$win_coin=$price+$user_coin;
mysql_query("UPDATE `tbl_users` SET `total_coin`='$win_coin' WHERE id='$user_id'");
mysql_query("INSERT INTO `tbl_rooms_win`(`room_id`, `u_id`, `win_date`, `price`, `win_status`) VALUES ('$room_id','$user_id','$date1','$user_coin','1')");
success_mail($user_id, $room_title, $user_coin, $win_coin);
$win[]=$win_coin;
}
}
mysql_query("DELETE FROM `tbl_buyroom` WHERE `room_id`='$room_id'");
}
else
{
while($no_winner=mysql_fetch_assoc($buyroom_query))
{
$uid=$no_winner['u_id'];
nowinner_mail($uid, $room_title);
$result="No winner";
}
}
}
}
}
}
在上面的代码中,我已经使用了睡眠方法。这种方法有效地进行了一段时间但很多次,如果它将同时睡眠1次抽签结果,那么另一个结果将会以更少的睡眠时间来进行。所以它停止为一个彩票工作。我希望你理解我的问题。请帮我解决一下