bPHP Posted April 25, 2010 Share Posted April 25, 2010 Hi! I'm programming a website that includes a chat, and I would like to know whether it would be convenient to use MySQL or memcache for messages between the users. I do not need to store the conversation messages... I'm on a VPS... I guess I could change the Apache max mysql connections to around 100 or 200, but maybe would be best just to use memcache? Thanks for any input! Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/ Share on other sites More sharing options...
canadabeeau Posted April 25, 2010 Share Posted April 25, 2010 depends how big its going to be, maybe memcache Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1047838 Share on other sites More sharing options...
bPHP Posted April 25, 2010 Author Share Posted April 25, 2010 It's going to have around 200 people chatting at the same time at all moments, maximum. It could grow rapidly though... Is it true that memcache is not that safe in terms of storing data? According to php.net: Memcache::set() stores an item var with key on the memcached server. Parameter expire is expiration time in seconds. If it's 0, the item never expires (but memcached server doesn't guarantee this item to be stored all the time, it could be deleted from the cache to make place for other items) Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1047842 Share on other sites More sharing options...
Philip Posted April 25, 2010 Share Posted April 25, 2010 With memcache, the reason it is great for temporary things (hence a cache), is that your items can get deleted yes. Reasons: a) There are too many items in the cache, thus it goes to the first thing item in the cache and overwrites it. So, if I put in (in this order) A B C D E F G and that's the max number of elements I can hold in my cache, then A would get deleted and H would take its place. Basically, it goes by order of last updated. b) Your server does, or the process for some reasons ceases to stop working. Memcache is not a permamant storage solution. However, you can use multiple memcache servers and run hotswapping on them (a bit tricky, adds redundancy, but increases time to pull/write from/to cache). If you are not worried about saving the conversations, and you can actively expand your memcache server count as your user base grows, and you understand that your users will have a limited history (e.g. things will be getting erased each time they send a message) then I don't see why you can't use it. Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1048150 Share on other sites More sharing options...
bPHP Posted April 25, 2010 Author Share Posted April 25, 2010 Actually, I'm erasing every message after it was read by the other party. Conversation tables are always empty, then get one message, this message is read, and gets erased. It works fine like that but using MySQL. If I have 200 people chatting at the same time, then I will have to store a maximum of 400 items in memcache. Looks like memcache can do the trick... But what is the maximum number of elements? How can I know that memcache won't erase one message of one of the users to put another one? The php.net documentation seems to be really vague about this, I don't want any messages from the users to be lost. Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1048163 Share on other sites More sharing options...
Mchl Posted April 25, 2010 Share Posted April 25, 2010 Why not start an IRC server + web client? Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1048176 Share on other sites More sharing options...
Philip Posted April 25, 2010 Share Posted April 25, 2010 Yeah, I also don't see why you don't use an actual chat program either. But if you continue with memcache, you decide the size of the storage. http://code.google.com/p/memcached/wiki/NewConfiguringServer Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1048198 Share on other sites More sharing options...
bPHP Posted April 25, 2010 Author Share Posted April 25, 2010 Thanks for the link, I'll make a memcache version and see how it goes. About using a chat program, I think I rather use my own... I'm learning a lot doing this, plus I will be able to change anything whenever I want to fit the users needs. Thanks for all the answers. Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1048204 Share on other sites More sharing options...
roopurt18 Posted April 26, 2010 Share Posted April 26, 2010 You might try looking at ActiveMQ. It's essentially a pub / sub mechanism. My coworker has been looking at it intently since HTML5 supports web sockets. Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1048892 Share on other sites More sharing options...
shedokan Posted April 30, 2010 Share Posted April 30, 2010 You can also save the messages in a file, like each file with the name of the conversation, and you can just empty it every time. Save the text in a file and other things like which users have read the file to know when to delete it you can use memcache, that way you'll save memory and minimize the chance of getting your memcache overwritten. Quote Link to comment https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1051249 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.