Page 1 of 1

dynamic data

Posted: Thu Apr 03, 2008 8:23 am
by xannaxprozaxx
Hello to all of you; this is my first post here; it is a question that might seem stupid, but I am no pro. I asked this same question on some other forum and got no answer, well I hope if it's THAT stupid at least you can tell me why it is.
Ok here it goes: I am developing my own range of web applications, for our internal website, including a chat client and whatnot. I intend to release all source codes for free under no license whatsoever as soon as they are good enough for me. I am a hobbyist coder, but I have more or less mastered actionscript 2, know a good deal of as3, I use ajax/js fairly easily and I know enough PHP to do whatever I want. I still call myself an amateur because I am learning those when I need them, for the requirements of a particular project. I am explaining all this because I don't want you to think I am a total idiot.
Because something puzzles me a lot: The only way I know of storing data and retrieveing it is by using SQL (...or text files...). This works for most applications, but I wonder if this is how it is done professionally, for, say, a chat client. I have developed functional chat clients cores, but what I do is I store user_sender/text/user_target and do a refresh on all clients every x seconds. It works for our internal website - we are only a handful of partners . But wouldn't it put a lot of strain on a server if this system is used on large-scale applications, or with many users? Is this how it is done, ideally?
In a nutshell, my question is: beside storing the data somewhere and refreshing the clients, is there a way to make the server send the data to the target client when needed?
Another question, a bit off-subject though: in the event I need quick data storing and retrieval, and I don't need any of SQL's features, is it virtually as efficient to retrieve them from a textfile?
Maybe my questions are basic, and I don't ask as much as a complete explanation. I can read and learn about technologies by myself, the only thing being, I don't know what to search for!
thanks in advance. I hope my English is clear enough.

Re: dynamic data

Posted: Thu Apr 03, 2008 8:38 am
by Mordred
xannaxprozaxx wrote: In a nutshell, my question is: beside storing the data somewhere and refreshing the clients, is there a way to make the server send the data to the target client when needed?
Another question, a bit off-subject though: in the event I need quick data storing and retrieval, and I don't need any of SQL's features, is it virtually as efficient to retrieve them from a textfile?
Maybe my questions are basic, and I don't ask as much as a complete explanation. I can read and learn about technologies by myself, the only thing being, I don't know what to search for!
thanks in advance. I hope my English is clear enough.
For HTTP-based architectures you can't do it by pushing data to the client, the client has to pull it.
IRC is push-based, it sends data only on demand and only to the clients who need it.

Database servers offer much more than data storage - data locking, scalability (transparently run a network of mysql servers instead of one), with the little of working with SQL. You can use non-SQL databases to avoid the overhead if you want. Also, databases can have in-memory tables for REALLY fast access.

File-based storage is not natively lockable, cannot work on many machines without heavy sync overhead, etc.

Re: dynamic data

Posted: Thu Apr 03, 2008 4:07 pm
by xannaxprozaxx
If I get it right, it depends on the protocol; If I want to create my own chat server, I'd have to develop my own protocol (or use IRC or some other existing protocol) and my own application. If I want a php-based chat client, I'd have to make the php communicate with some cgi application on the server. Please correct me if I am wrong.
Thanks a lot for answering!

Re: dynamic data

Posted: Fri Apr 04, 2008 1:46 am
by Mordred
xannaxprozaxx wrote:If I get it right, it depends on the protocol; If I want to create my own chat server, I'd have to develop my own protocol (or use IRC or some other existing protocol) and my own application. If I want a php-based chat client, I'd have to make the php communicate with some cgi application on the server. Please correct me if I am wrong.
Thanks a lot for answering!
Yes and no.
If you write your own client and server, you can do whatever you like.

If, on the other hand, you want to use PHP for a browser-based chat over HTTP, you have to make the clients (i.e. browser) "ping" the server (i.e. the PHP script) asking if there is new chat data. (i.e. the "pull" model). The PHP is the "some cgi application on the server" you speak about.

Some people implement "push" model (i.e. like IRC) browser chat by using Java applets.

Re: dynamic data

Posted: Fri Apr 04, 2008 4:05 am
by xannaxprozaxx
ok ok I get it I think now. I wasn't having a picture clear enough of how all of this works to understand what php was. I have a much better understanding now. Thanks to your clear and concise answers, I was able to find the articles needed. Thank you!

Re: dynamic data

Posted: Fri Apr 04, 2008 7:11 am
by anto91
if your writing a chat application you could use ajax, its works extremely well and i have a working chat with user list and messages.

Re: dynamic data

Posted: Fri Apr 04, 2008 7:26 am
by Mordred
anto91 wrote:if your writing a chat application you could use ajax, its works extremely well and i have a working chat with user list and messages.
On the contrary, for many clients it will be hugely ineffective, as the OP already discussed.

Re: dynamic data

Posted: Fri Apr 04, 2008 7:54 am
by xannaxprozaxx
if your writing a chat application you could use ajax, its works extremely well and i have a working chat with user list and messages.
No, see, that's my problem. Sorry if I wasn't clear enough (I am not a native English-speaker).
See, with Ajax, you have to set a certain refresh rate to your client. In most tutorials, 3 secs is advised, I've lowered it to 1 sec in my own Ajax client because I don't have much users. But see, even 1 sec is far from being real-time chat. How would you do a ICQ-old-style-chat (you know, where you used to see the letters typed by your contact) with a refresh rate of 1 sec? I can write a whole sentence and erase it in 1 sec. And if it is 3 secs, that's worse:
consider for example the server you're connected to went offline. your client waits 3 secs, then refreshes, doesn't get a signal. Retries, doesn't get a signal, then notifies you that you are offline. That's 6 secs. If your code is well-done, you've implemented a function for direct refresh after a failed attempt, so it's still 4 secs.
Let's say you want to do a multiplayer game which needs reflexes, precise timing, or a game where you have to guess a word within a certain timeframe...
A last example: you let your browser opened for a full day but no one speaks with you, and you don't speak to no one. You're still accessing the database each 3 secs for nothing. multiply this by a thousand users...I don't know if it would put a lot of stress on the server, but I just don't like it. It's not "clean coding". Dunnow how to put it any other way.
Hope that explains my problem a little better. If not, well, that's my limit in English, sorry!