Tikasas Posted October 18, 2011 Share Posted October 18, 2011 Hello everyone, im new here. so to begin with i wanted to ask you about my realtime chat script im creating. You can check it out here http://madnet.us.lt/chat.php. Please! i repeat PLEASE, dont use any tags or sumtin in input fields, the chat is still unsafe! It only works in some versions of Opera, Mozila(best) and i think it should work on Chrome, but god no ,dont use IE This is my first project i created so dont judge me if the code sounds stupid to you:D I made this using php/html/jquery and css . My first problem is that i used timeout function for chat div refresh, i dont think its the best way to get data from mysql, couse if like 500 or more people will get refreshes every 1 second, i think the server would crash, maybe you could get me through this with an alternative. Another problem is as i mentioned before that this chat is not capable with all explorers people use today. Third problem is that i cant figure it out how to make the public and clan buttons work (i only manage to get one of them work, if i make another one work then they conflict(nevermind you will see in the code)). I got a lot of more questions about security and stuff. but for now i would like to get the answers how to fix these things. Now il share you the code. I will accept all you advices so be free to say anything you think would be better for my real time chat. Im attaching the chat files.You will find the mysql tables in the zip Many thanks! [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 18, 2011 Share Posted October 18, 2011 First of all, if you are looking for people to beta test your project, there is a forum and procedures for that. As for the specific issues you are having, what steps have you taken to debug the problems and what were your results. I for one am not willing to download and read through all your files to try and figure out what the problems might be. It is your program and you should be able to know what decision points in the logic that could cause your problems. You need to add debugging code to see what the values are compared to what you expect them to be. Then you can isolate the exact cause of the problem. My first problem is that i used timeout function for chat div refresh, i dont think its the best way to get data from mysql, couse if like 500 or more people will get refreshes every 1 second, i think the server would crash, maybe you could get me through this with an alternative. How often you check the server for updates its up to you. 1 second sounds reasonable. Will that crash your server? Not likely. But, I don't know what the specs are for your server or the traffic it gets. You absolutely should be using a timestamp in order to ONLY get new content instead of all the content for the thread when you make a call though. SO, in most cases the client will make a request of the server, the server then finds there was no new content and simply returns a '0' (to indicate false) or some other very small piece of data. Quote Link to comment Share on other sites More sharing options...
Tikasas Posted October 18, 2011 Author Share Posted October 18, 2011 naaah i dont want you to test my project(sorry if i cant expres myself right. Sorry for my english), i just don't know how to make everything work right. How often you check the server for updates its up to you. 1 second sounds reasonable. Will that crash your server? Not likely. But, I don't know what the specs are for your server or the traffic it gets. You absolutely should be using a timestamp in order to ONLY get new content instead of all the content for the thread when you make a call though. SO, in most cases the client will make a request of the server, the server then finds there was no new content and simply returns a '0' (to indicate false) or some other very small piece of data. every 1 second it checks if my old content is equal to database content and it shows the new data only when old data is not equal the new one. You said "ONLY get new content instead of all the content" so is it doing it right? P.S. i asked you not to use any tags in my chat Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 18, 2011 Share Posted October 18, 2011 every 1 second it checks if my old content is equal to database content and it shows the new data only when old data is not equal the new one. You said "ONLY get new content instead of all the content" so is it doing it right? No. Since this will be checking for updates frequently you want to keep the amount of data being sent and returned from the server to an absolute minimum. So, one solution is to use a timestamp. In the PHP script you would get the timestamp of the time you first grab results for a user. And, in addition to sending those results to the client you would also send the timestamp. Then when the client does a check to get new content it ONLY sends the timestamp. The server checks to see if there is any new content since the timestamp passes and sends the results and a new timestamp. The JavaScript code will append the new content to the existing content and store the timestamp for the next request to the server. So, when there is no new content, the only thing you are passing back and forth is the timestamp. P.S. i asked you not to use any tags in my chat Yeah you did. But I like to make things break. For what it's worth your didn't break. But, you should be running the content through htmlentities() or htmlspecialcharacters() before sending back to the client. Quote Link to comment Share on other sites More sharing options...
Tikasas Posted October 18, 2011 Author Share Posted October 18, 2011 how do you think what would be the minimum server requirements for this kind of chat for like up to 1000-2000 users? No. Since this will be checking for updates frequently you want to keep the amount of data being sent and returned from the server to an absolute minimum. So, one solution is to ... hmm, that would save a lot of bites. How do i check if theres a new timestamp value in the database? i asume that every message should have a timestamp then? or how the timestamps checks the new content? or i didn't understand you correctly? Yeah you did. But I like to make things break. For what it's worth your didn't break. But, you should be running the content through htmlentities() or htmlspecialcharacters() before sending back to the client. well that would be the least i can do for security, i think somehow it should be able to secure the chat box even more . damn, someone already did break my chat. Thanks for your response. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 18, 2011 Share Posted October 18, 2011 how do you think what would be the minimum server requirements for this kind of chat for like up to 1000-2000 users? No idea. It would be based on how efficient you make it (which doesn't sound too efficient at the moment), the server specs and the available bandwidth. You would need to do some load testing to find how many users you could support. How do i check if theres a new timestamp value in the database? i asume that every message should have a timestamp then? Your messages should have a timestamp of when they are created. So, you use the timestamp to get all new messages using a query such as SELECT message FROM message_table WHERE create_time > '$timestamp' ORDER BY create_time Quote Link to comment Share on other sites More sharing options...
Tikasas Posted October 29, 2011 Author Share Posted October 29, 2011 hmm, hi there again, got some problems fixing my chat. now i get the old messages (all of them) by taking all the content from my chating box, and i refresh some php file for getting the new messages, i add the new messages to an invisible div. and then theres a function if Oldmessages==Newmessages do nothing, else update chat with new messages .. the question is , how do i get the last message timestamp from it? i think everything should be made diffrently, give me a hint.. thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 30, 2011 Share Posted October 30, 2011 I think I already explained that. You need to generate the timestamp in the PHP code when you query the database and then send that timestamp back to the AJAX with any updated messages. Then the JavaScript should send that timestamp back on the next trip so the PHP code only gets new messages. Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 30, 2011 Share Posted October 30, 2011 please fix your chat. i cant try it out. Quote Link to comment Share on other sites More sharing options...
Tikasas Posted October 31, 2011 Author Share Posted October 31, 2011 you can try it out again, till anyone else brakes it to busy to upload chat done with html special chars. Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted October 31, 2011 Share Posted October 31, 2011 its anonymous no anonymus Quote Link to comment Share on other sites More sharing options...
Tikasas Posted October 31, 2011 Author Share Posted October 31, 2011 well, sorry for my english:) Quote Link to comment 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.