Jump to content

Anyone know alot about using fputs function


Shadowing

Recommended Posts

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);

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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?

Link to comment
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.