Sinikka Posted December 10, 2008 Share Posted December 10, 2008 I have a cron setup through cronjobs to restock shops at certain times through out the day and the cron works correctly with one exception. For about a minute from the time the cron executes it seems to be refreshing continually when it's only supposed to refresh the stock one time. If anyone could possibly help me with why it's doing this I'd appreciate it very much. <?php #!/usr/bin/php $dbh=mysql_connect ("localhost", "DBNAME", "DBPW") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("DBNAME"); $findItems = mysql_query("SELECT * FROM shop_items2 WHERE game = '1'"); while ($getItems = mysql_fetch_array($findItems)) { $id = $getItems[id]; $getItems[max_stock] = round($getItems[max_stock] / 3); $rand[$id] = rand(0,$getItems[max_stock]); } foreach ($rand as $id => $val) { $sql2="UPDATE `shop_items2` SET cur_stock=ROUND((max_stock/3) * RAND() ) WHERE game = '1' "; mysql_query($sql2); } echo $sql2; ?> Quote Link to comment Share on other sites More sharing options...
ok Posted December 10, 2008 Share Posted December 10, 2008 Sinikka the most decisive solution for this is to contact your web hosting company. Different hosting company provide different settings for this matter. Quote Link to comment Share on other sites More sharing options...
Sinikka Posted December 14, 2008 Author Share Posted December 14, 2008 Ok, I contacted my hosting server and was told that the crons are setup properly and that the problem is with the script. I can't find anything within my script posted above that would continually refresh the stock. Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted December 14, 2008 Share Posted December 14, 2008 Did you mean that it duplicate values for the same entry on each cron run. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted December 14, 2008 Share Posted December 14, 2008 I think I see the problem. In your UPDATE query, you don't actually use an ID in your WHERE clause so it ends up updating EVERYTHING on each pass of the foreach loop. =/ Also, you need to put the shebang line as the first line in the file for it to do anything I think. Quote Link to comment Share on other sites More sharing options...
Sinikka Posted December 19, 2008 Author Share Posted December 19, 2008 I think I see the problem. In your UPDATE query, you don't actually use an ID in your WHERE clause so it ends up updating EVERYTHING on each pass of the foreach loop. =/ Also, you need to put the shebang line as the first line in the file for it to do anything I think. Thank you, I'll try adding in a query for each shop and see if that stops the continual updating. What do you mean by the shebang line? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted December 19, 2008 Share Posted December 19, 2008 #!/usr/bin/php That's called a shebang line. Quote Link to comment Share on other sites More sharing options...
Sinikka Posted December 22, 2008 Author Share Posted December 22, 2008 I tested it with just one shop restocking only with the id added in and it still refreshes continually for a full minute. I'm at a complete loss with things to try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.