Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 08-05-2011, 09:22 PM Active Checking
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
I'm not exactly sure how to title this thread, or even where to put it. This is a problem that has had me wondering for a while now, and I'd finally like to put that to rest

My question is this:

How can I send data to an external page, and have it run a function in another user's browser?

It's kind of complicated without an example, so here's a real-world example:

2 people are in a chat room
Person 1 sends a message
Person 2 gets the message

...Simple as that, right? Well, I thought so too, until I actually tried coding a chat script. I came to the part where Person 2 receives the message, and was stumped. How could Person 2's script possibly know there's a new message waiting to be loaded without checking for one? Person 2's script would have to check the file a few times per second to get an accurately updated chat log, which is very heavy on the server.

I'm assuming that professional chat rooms don't work like this. Person 2's script would receive a piece of data telling it to update the script, and it would. But how would you do that, again, without checking every second?

Thanks,

-PG
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-06-2011, 05:37 AM Re: Active Checking
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Can't be done with PHP.

"chat" apps are most commonly written as a Java applet (Java not javascript) that runs on the client JVM and communcates with the server.

You can sort of do the same with javascript and the XMLHTTPRequest object but it will eat resources and can crash some browsers after a few minutes.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-06-2011, 10:09 AM Re: Active Checking
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
Ah, I didn't know most were written in Java. Thanks, Chris!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!
Physicsguy is offline
Reply With Quote
View Public Profile
 
Old 08-08-2011, 03:49 PM Re: Active Checking
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Quote:
Originally Posted by Physicsguy View Post
Ah, I didn't know most were written in Java. Thanks, Chris!
While this can't be achieved by PHP on it's own, you can do this with JavaScript / HTML5.

HTML5 demos has a really good example of this being achieved via web sockets.

As chrishirst mentioned though, you could use a pull method where you get JS to load an ever changing file every few seconds (but it's an epic resource hog).
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Reply     « Reply to Active Checking
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24303 seconds with 12 queries