Jump to content

Archived

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

mre2mpo

Inserting data simultaneously into a mysql database

Recommended Posts

The problem is I have a database table that keeps track of people who are online (how have been active in the last 5 mins). A php script is run when ever they click a link on the page and it inserts the user into the database and delete all entrys that are over 5 minutes old.

 

The problem occurs when two users click on a link at almost the same time. This runs the script but only one of them is entered in the database the other is shown a defined error message \"Error inserting into database\".

 

Any ideas how I can get round this problem. I would really like know a fix for this problem as it will be helpful for a later day but is there a better way of find out who is online.

 

Michael

Share this post


Link to post
Share on other sites

Well, that shouldn\'t be a problem I wouldn\'t think, unless your host is slow. MySQL is pretty fast :S

 

But maybe you could have the values stored into a .txt database to beginwith, and then have a script read through the values of that, and insert them into the DB.

Share this post


Link to post
Share on other sites

explore the tutorial(s) here on using CRONTAB, this would be an appropriate occasion, to take a substantial load off your server, the file would run once every five minutes and do all the inserting then, unless you WANT to log all the movements of visitors (kinda pointless, when there are awstats and webalizer and such)

Share this post


Link to post
Share on other sites

×

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.