Shadowing Posted May 25, 2012 Share Posted May 25, 2012 Ive started to use the function "fputs" And I was wondering about something. I'm adding text to a file for a chat system and I was wondering what happend if a user opens a file at the same time another user is and it overwrites it? or is that even possible. is it first come first serve basic? $open = fopen($chat_buffer, "a"); fputs ($open, $filtered . "\n"); fclose ($open); Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/ Share on other sites More sharing options...
ManiacDan Posted May 25, 2012 Share Posted May 25, 2012 Yes, that's why the database was invented. Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348579 Share on other sites More sharing options...
Shadowing Posted May 25, 2012 Author Share Posted May 25, 2012 thanks for the reply ManiacDan I read it wasn't a good idea to use mysql for a ajax chat system. Specially since im using it heavy for other things. i close the file right after i open it. so that can still lead to two people opening it up at the same time? Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348611 Share on other sites More sharing options...
ManiacDan Posted May 25, 2012 Share Posted May 25, 2012 I read it wasn't a good idea to use mysql for a ajax chat system. There was most likely a "because" in whatever you were reading. You should be using memcache if this is a chat system. Flat files are slower than databases, not faster. so that can still lead to two people opening it up at the same time?What it will lead to is either: A) Two people opening it at the same time B) The second person waiting for the first person to be done using it Either one is bad. Look into something like rabbitmq for passing small messages between scripts. Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348628 Share on other sites More sharing options...
Shadowing Posted May 25, 2012 Author Share Posted May 25, 2012 Well damn lol. thanks alot for that information. maybe i'll just do mysql route and if i see issues then learn how to use rabbitmq. looks like there is alot to it. This is how im doing it now with flat files which i will now change to mysql but anyways. a jquery script looks for updates every 5 seconds. if there was a update then it grabs the new lines of chat. when a user submits a chat it updates then and there. This way it appears to the user that the chat is instant but really its not. Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348647 Share on other sites More sharing options...
ManiacDan Posted May 25, 2012 Share Posted May 25, 2012 Yep, that's how chat works. Your "storage" area for incoming chats needs to be as fast as possible. Message queues are the fastest possible medium for this, but MySQL should be fine since I doubt you'll have more than 10 people on this service. Remember to periodically wipe the table, clearing out any chats older than a few hours. Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348650 Share on other sites More sharing options...
Shadowing Posted May 25, 2012 Author Share Posted May 25, 2012 idk my site www.stargatesystemlords.com gets aroudn 400 ticks a day so your saying that couldnt support even 50 people? Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348652 Share on other sites More sharing options...
ManiacDan Posted May 25, 2012 Share Posted May 25, 2012 What's a "tick"? How often are you expecting them to chat? The chat system I wrote handled 20,000,000 messages a day. Yours, probably less than that. If there's fewer than 5 messages per second, you'll be fine with MySQL. I don't know enough about the rest of your infrastructure to be more accurate. Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348653 Share on other sites More sharing options...
Shadowing Posted May 25, 2012 Author Share Posted May 25, 2012 tick as i page views sorry. not sure why i said tick lol. So probably be alright to start me off then later switch over to something else. Plus i'll beable to see limits first hand lol thanks for the help ManiacDan. Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348657 Share on other sites More sharing options...
salathe Posted May 25, 2012 Share Posted May 25, 2012 The chat system I wrote handled 20,000,000 messages a day. Mine handled several orders of magnitude more! Shame it never went into production. Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348658 Share on other sites More sharing options...
Shadowing Posted May 25, 2012 Author Share Posted May 25, 2012 maybe i can write something to load test it Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348660 Share on other sites More sharing options...
ManiacDan Posted May 25, 2012 Share Posted May 25, 2012 The chat system I wrote handled 20,000,000 messages a day. Mine handled several orders of magnitude more! Shame it never went into production. Haha did you really? I actually wrote some of the message-passing stuff for a really big social network (100,000+ clicks per second), so I wasn't just randomly saying things. How did you write yours? What did you use? Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1348665 Share on other sites More sharing options...
Shadowing Posted May 28, 2012 Author Share Posted May 28, 2012 Hey ManiacDan I was looking some stuff up today and came accross some stuff on mysql displaying what Memory was on table type. so if i used memory instead of InnoDB for the chat system wouldnt it be faster? doesnt it mean its all being stored on the servers memory? Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1349349 Share on other sites More sharing options...
ManiacDan Posted May 28, 2012 Share Posted May 28, 2012 MEMORY table types are faster, yes. They only exist in RAM (unless swapped to the disk) and will be destroyed entirely when you shut down mysql. Memcache is still faster. Quote Link to comment https://forums.phpfreaks.com/topic/263117-anyone-know-alot-about-using-fputs-function/#findComment-1349364 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.