sonny Posted July 22, 2009 Share Posted July 22, 2009 Hi I have a cron Job that calls a php page that deletes old Msql data every 5hrs or so I have been thinking what would be the more efficient way to do this, at the time of display or time of insertion, or just keep doing it via cron job? I have a php page that displays data $query=" SELECT * FROM visits WHERE page='$page' && vcode='1' ORDER BY id DESC LIMIT 20"; $result=mysql_query($query) or die(mysql_error()); while($row =mysql_fetch_array($result)) and another php page that inserts it $queryup="UPDATE visits SET vcode='0' WHERE ip='$ip' && page='$page'"; $resultup=mysql_query($queryup) or die(mysql_error()); $query="INSERT INTO visits VALUES('NULL', '$ip', '$refer', '$page', '$flag', '$country', '$region', '$city', '$now', '1')"; $result=mysql_query($query) or die(mysql_error()); Looking for advice, on the most efficient and safest way to remove old data Thanks Sonny Quote Link to comment https://forums.phpfreaks.com/topic/167027-advice-on-deleteing-msql-data-efficiantly/ Share on other sites More sharing options...
ldougherty Posted July 22, 2009 Share Posted July 22, 2009 Honestly it wouldn't make a difference as you are running a query to delete the data in both methods. It all depends on how often you do it. You are either running a query to remove more results once every couple hours or running multiple queries more often to remove less results. I'd stick with the method you are already using, less queries = better performance Quote Link to comment https://forums.phpfreaks.com/topic/167027-advice-on-deleteing-msql-data-efficiantly/#findComment-880731 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.