Hi,

I'm working on a project which requires some sort of 'connection' between 2 (or more, actually) clients. Basically one person should be able to send data to another person with their webbrowser, somewhat comparable to a instant message system.

My first idea was using XHRs to send data to the server, and let PHP store this data in a MySQL table. Later, the other client would use an XHR to request data from the server. The server then sends back all data so the client can use it.

The fact that I'm constantly pulling data shouldn't be a big problem, but I was wondering if there is a better way to achieve this sort of communication. The data doesn't have to be stored for more than a few seconds, so the MySQL database would only function as some sort of buffer. On the other hand, there is (as far as I know) no way to directly send data to another client, but perhaps some of you could have some suggestions for me.

Thanks in advance.

Member Avatar for diafol

The data needs to be stored/processed somewhere - *I think*. So a server needs to be involved. I can't think of a way to force data down the throat of another machine, through normal methods. Bit of a security risk? Personally I'd stick with the server/db method. If you're using php the webserver's involved anyway. I've used ajax in the past to make chat apps. Comet is probably a better method, although (in my experience) fiendishly difficult to set up.

I've looked into Comet a bit, but it doesn't really look like a clean way to do *anything*, in my opinion at least.

Another thing I was curious about are application variables. Unfortunately, that's something PHP does not have. Scripts mimicking this idea generally use files to write data to, which is probably not better than using a database.

Aren't there other ways to temporary store small pieces of data? I know a database should work fine for what I'm trying to achieve, but it seems a bit... overkill.

Member Avatar for diafol

AFAIK, you can store data via file and DB. Files include cookies. You could write to cookies, but that info would have to be passed through server storage somehow (file?)

IMHO - you have two options, db or file. I'd use ajax, although Java might be worth a shot. I know almost nothing about it though.

Well, there's also the option of having a forked php daemon with a unique id stored for each "conversation". I did this once with php for the daemon and flash for the interface. It creates a socket connection, and that's about as direct as you can get.

Although a socket connection would be better and a lot easier than pulling the data with periodical AJAX requests, I'm unable to use Flash (or any sort of plugin for that matter) in this project.

It seems I'll have to go with either a file or database then. Thank you for your replies (:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.