Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,479 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,680 people online right now. Registration is fast and FREE... Join Now!




Delete if

 
Reply to this topicStart new topic

Delete if

JBrace1990
2 Jul, 2008 - 01:49 PM
Post #1

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 476



Thanked: 22 times
Dream Kudos: 350
My Contributions
right now, i'm setting up an alert system for a Flex Chat i'm developing... it uses PHP as a backend to output XML data...

now, i figured out (i think) how to make the alert appear, but i'm having a bit of a writers block...

see, when everyone online at the time the alert is sent gets it (less then 2 seconds total), I want the entry deleted... but at the same time, I need to make sure EVERYONE saw it... so i'm not sure how to do it...

for example, an alert is added when 5 people are online... I want to make sure all 5 people see it (even if there is lag)... now it has a 1 second update (think chat, you want it in somewhat real time), though I can make an additional update that goes like every 5 seconds...

i'm just having trouble thinking of this... can anyone offer a new perspective?
User is offlineProfile CardPM
+Quote Post

joeyadms
RE: Delete If
2 Jul, 2008 - 05:36 PM
Post #2

D.I.C Head
Group Icon

Joined: 4 May, 2008
Posts: 145



Thanked: 7 times
Dream Kudos: 600
Expert In: PHP, Web Security

My Contributions
I havent worked with chats really, but I thought I'd throw my thoughts in, maybe it will spark something in your mind?

the illusion of realtime is done by asynchronous requests every 1 second. What you could do is just have a javascript function to evaluate alert times or something.

So that if the timestamp of an alert is 3 seconds or so old then to not show it.

You could, in theory, make a more robust platform where the last request timestamp is stored in a javascript var, and if the returned alert timestamp is in between requests, then you can display it for x seconds.

Or you could store alert Id's in an array or such, and only display alerts not in that array.

Like I said i'm far from pro at chat apps, but its something to get you thinking.
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Delete If
2 Jul, 2008 - 06:32 PM
Post #3

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,023



Thanked: 81 times
Dream Kudos: 1175
My Contributions
If you wanted to make sure that everyone saw it ou could set up a separate php file with a separate xml request going to it, and then have it popup a box saying the alert message when there is one. Then when the user clicks the ok/cancel button (or whatever) it sends an item to the database that basically says the user has seen the alert. Thatway you can set it to only look for alerts that haven't been seen by the user, and update in real time. Though this will probably eat up more CPU and everything as it would be having 2 queries to the server per second.
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Delete If
2 Jul, 2008 - 08:19 PM
Post #4

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 476



Thanked: 22 times
Dream Kudos: 350
My Contributions
2 is nothing compared to this >.>;; try like 12 per second yinyang.gif

anyway, before you posted it Betawar, I actually went ahead and did that lol... i added an alert.php that checks for the latest alert, and checks the status of the users "readAlert" field... if it's no, it displays the alert, else it displays nothing.... actually, the XML outputs <poster>fake</poster><content>fake</content>, but I have the flex App ignore it =p
User is offlineProfile CardPM
+Quote Post

BetaWar
RE: Delete If
2 Jul, 2008 - 08:38 PM
Post #5

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,023



Thanked: 81 times
Dream Kudos: 1175
My Contributions
Wow, okay I guess that explains some of the browser slowness smile.gif
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Delete If
3 Jul, 2008 - 06:19 AM
Post #6

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 476



Thanked: 22 times
Dream Kudos: 350
My Contributions
yeah.... i don't really know how to speed it up, but i'm gonna try to cut down on the amount of queries...
User is offlineProfile CardPM
+Quote Post

JBrace1990
RE: Delete If
3 Jul, 2008 - 07:51 AM
Post #7

D.I.C Regular
Group Icon

Joined: 9 Mar, 2008
Posts: 476



Thanked: 22 times
Dream Kudos: 350
My Contributions
ok, next question.... when someone enters the chat (logs in), a message is added to the database that says "$x Has entered".... I need a way to add "$x has left"... i'm thinking of maybe doing a javascript call to a php function? but idk...

I could get it to work if I added a logout button, but then people who just close the window (like me), won't be marked as having left...

any ideas?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 06:31PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month