Jump to content

Archived

This topic is now archived and is closed to further replies.

radalin

instant messaging with php

Recommended Posts

Yeah everyone who reads the subject will think that idea sucks. It's impossible, even if it's done it will be slow and there is no way you can do it with php, but only php.

Well yes I think it will be quite hard and a couple of articles I had read about it convinced me that the idea was sucks :) But none of them had implemented XMLHttpRequest object in them. So that's where the idea becomes more intresting of course.

I would like to discuss it with you about it. How can we make it, if we can how it will be it's perfomance.

Some things that comes to my mind XMLHttpRequest (I will call it ro after this) will check every 30 seconds if there is a new message or not. If there is, a pop-up window or something like that will show as a conversation is started, ro will start checking if there is a new message or not every 5 seconds. Here's the first problem what if there is 3 conversation is going on. The whole thing collapses because only 2 connection allowed at a time. Well a possible solution will be to send conversation id's with ro and then get messages of that conversation according to the id and with one connection we are done with that too.

So we go on with message posting. How the heck we can do it. Yeah the user will write it's message and then press the submit. So as he press post button, we disable entring anymore entries and disable post button. We send the data via ro and then enter it to the db then we return the new messages and then add to the messaging log of the im window. And the 5 second is reset.

Well here comes another problem, what will happen if the conversation is ended. Everything is cool if he click on the cross, kill the conversation id and no more check about that. What if it becomes to a timeout, if he does not click on that cross. After a couple of trying which does not return any new messages I can suspend the conversation id and then return that id to the 30sec check. And everything can be cool from there.b When a new messeage is returned from ro after 30 sec we then return to the 5 sec loop. A problem can occur if one clicks on the cross and one doesn't. One's conversation id is killed and the other's is suspended. But as the other's id is killed there is no way that suspended id can take anymore responses. So there will be lot's of im windows in the browser which belongs to the conversation with the same person. So I also just add the user ids. If the suspende conversation id's user ids (the one that talk and the one that reads) match with the new new message then add the new message to the message log then put the conversation id in the 5 sec loop again.

This are possible things that can happen and possible solutions I have found. I'm sure that I'm missing something. The JS code will be huge perhaps which will really be a problem, and it will require a good connection at the user side and a good server which will handle requests from lots of computer nearly every 10 sec or something.

I also welcome other solutions without php but via irc (which I think it will be easier for me but I'm not sure how I can protect it.) or java applets (msn web messenger wasa based on something like this I think.) or another thing that I do not know.

Any comment or idea is welcome.

Share this post


Link to post
Share on other sites
Sounds good. However I recently found [url=http://www.unwieldy.net/ajaxim/]ajax im[/url] it is very good.

Share this post


Link to post
Share on other sites
That's exactly what I was thinking of. At least that now I know that it can be done. Thanks buddy.

Share this post


Link to post
Share on other sites
Theres not much php can't do if you put your min dto it. I have a 2 webservers running here written entirely in php.

Share this post


Link to post
Share on other sites
Ajax is not so much php as it is javascript.

Share this post


Link to post
Share on other sites
Yeah everything can be done, but the time and the result worths it? That's the problem, I was willing to discuss if such a im could be done and even if it's done how would be the performance. And the link wildteen had given me, showed me that result would worth it. :)

But ajax is not much JS. There is only a XMLHTTPRequest Object and that's all. Total ajax js code is nearly 20 lines or something. And parsing the data you got is not that much if you use JSON or XML.

Share this post


Link to post
Share on other sites
It's already been done, using PHP and Javascript, long before the term AJAX was even a twinkle in anyones eye. AJAX is NOT new....it's a phrase that was recently coined for something that developers have been doing for a long long time.

We've had a PHP IM system running where I work for 3/4 years that uses javascript (not XMLHttpRequest mind) to get messages realtime for the user that is logged in. To be honest, there's really no point using PHP for something like this, it's not the best tool to get the job done. Knowing which tool to use to complete your job better is a major part of being a good developer.

On the other hand, if you want to do it for the sake of having done it, then go ahead :), It can't harm in learning how "AJAXY" stuff works so you can then use it in other projects in the future, just be aware that you're not doing anything that hasn't already been done :)

Share this post


Link to post
Share on other sites
Sigh, yeah even the best idea that comes to your mind had already been thought by someone else and even realized (just like in this case:)). Yeah that's quite true :). I have lost of my enthousiasme to make something that nobody has done years ago, aaaah, poor me :)

But I'm a bit confused on your words that there is no point using PHP. Then you should have done something very different than what I thought. Javascript cannot execute sql queries (even it can, sql server's username and password is seen which is vert problematic for security) so you should be using something different then writing to db and then fetching it. I'm curious about that and I would be glad if you talk about it even a little :)

Share this post


Link to post
Share on other sites
[quote author=radalin link=topic=105522.msg421869#msg421869 date=1156503531]
Sigh, yeah even the best idea that comes to your mind had already been thought by someone else and even realized (just like in this case:)). Yeah that's quite true :). I have lost of my enthousiasme to make something that nobody has done years ago, aaaah, poor me :)

But I'm a bit confused on your words that there is no point using PHP. Then you should have done something very different than what I thought. Javascript cannot execute sql queries (even it can, sql server's username and password is seen which is vert problematic for security) so you should be using something different then writing to db and then fetching it. I'm curious about that and I would be glad if you talk about it even a little :)
[/quote]

The javascript did not execute SQL queries...it can't....The javascript was used to call a "background" php script to connect to the db and check for new messages in a very ajax style manner....which is exactly what you would need to do with this...albeit you might choose to use the XMLHttpRequest object and make it "true ajax"...god i hate that term :)

Share this post


Link to post
Share on other sites

×

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.