Jump to content

cron jobs php


grlayouts

Recommended Posts

Ok i have my own online game..

 

every 15 mins it should pay out 15 energy with the code

 

<?php
$time=time();
include("config.php");
mysql_query("update players set energy=energy+15");
mysql_query("update players set energy=750 where energy>750");
mysql_query("update players set hp=max_hp");
mysql_query("update players set ops=ops+1 ");
mysql_query("update players set ops=150 where ops>150");
  if(!mysql_fetch_row(mysql_query("SELECT cronjob FROM cronjobs WHERE cronjob='turns';"))){mysql_query("INSERT INTO cronjobs VALUES ('turns','$time');");}
else{ mysql_query("UPDATE cronjobs SET lastran=$time WHERE cronjob='turns'");}

?>

 

however the problem is that its payout twice. but i only have it as one cron job..

 

any idea's?

Link to comment
https://forums.phpfreaks.com/topic/36541-cron-jobs-php/
Share on other sites

<?php
$time=time();
include("config.php");
mysql_query("UPDATE players SET energy=energy+15");
mysql_query("UPDATE players SET energy=750 where energy>750");
mysql_query("UPDATE players SET hp=max_hp, ops=ops+1");
mysql_query("UPDATE players SET ops=150 where ops>150");
if( mysql_num_rows( mysql_query("SELECT cronjob FROM cronjobs WHERE cronjob='turns';") )<1 )
{
       mysql_query("INSERT INTO cronjobs VALUES ('turns','$time');");
}
else{
       mysql_query("UPDATE cronjobs SET lastran=$time WHERE cronjob='turns'");
}

 

I just refactored the code a bit, could you log something to a file to check if the script is running twice somehow?

Link to comment
https://forums.phpfreaks.com/topic/36541-cron-jobs-php/#findComment-174018
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.