Jump to content

Recommended Posts

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!

 

Link to comment
https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/
Share on other sites

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)
Link to comment
https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1047842
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1048150
Share on other sites

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1048163
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1048204
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/199634-mysql-or-memcache/#findComment-1051249
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.