SchweppesAle Posted October 21, 2009 Share Posted October 21, 2009 Hi, I'm using AJAX to execute a script every time a user visits the page. The script reads an xml file then tallies the counter for each page view, however I'm a little worried about multiple users reading the file then adding one to the counter. Ex: User1 sees the counter set to 2 User2 sees the counter set to 2 then adds 1 = 3 User1 adds 1 to counter = 3(instead of 4). I guess my concern is that users will be reading and writing to this file synchronously rather than asynchronously. Should this be an issue? Link to comment https://forums.phpfreaks.com/topic/178518-writing-xml-apache-server-ajax/ Share on other sites More sharing options...
JAY6390 Posted October 21, 2009 Share Posted October 21, 2009 Use a database for this instead, and log every visit as a single row in a table. It's far better for statistics Link to comment https://forums.phpfreaks.com/topic/178518-writing-xml-apache-server-ajax/#findComment-941467 Share on other sites More sharing options...
SchweppesAle Posted October 21, 2009 Author Share Posted October 21, 2009 Use a database for this instead, and log every visit as a single row in a table. It's far better for statistics that was my original intention...won't this cause too much strain on the server though? AJAX is used to execute the script for each banner on our site. Meaning if we choose to display 6banners, that's 6 queries for every page view. I figured I could reduce this substantially by storing each entry into an xml file then setting up a cron job to read and store the entries within our db. Just not at all sure if the fwrite() and fread() functions are configured to access files asynchronously. Link to comment https://forums.phpfreaks.com/topic/178518-writing-xml-apache-server-ajax/#findComment-941489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.