Nathan,
The most common way to do what you described is with a technique called
long polling. Its where the client sends a request to the server and the
response comes back after some event on the server takes place. The
server doesn't respond right away by design, it just sits and waits for
some event to be triggered and sends the proper response based on the
trigger... Sometimes things are happening fast and so it doesn't feel so
long, but for a chat type client where there could be minutes or longer it
will leave it open for response. There can be a time out in which case
the client would just send another request every so often. This has more
to do with javascript and less to do with the server side scripts. PHP is
a server side rendering script language... once the client gets ahold of
the page, its javascript or html post that has to trigger the next move.


Thanks
Bryce Martin
Programmer/Analyst I
570-546-4777



Nathan Andelin <nandelin@xxxxxxxxx>
Sent by: web400-bounces@xxxxxxxxxxxx
11/30/2010 07:43 AM
Please respond to
Web Enabling the AS400 / iSeries <web400@xxxxxxxxxxxx>


To
Web Enabling the AS400 / iSeries <web400@xxxxxxxxxxxx>
cc

Subject
[WEB400] What is Event Driven Programming, its uses, & how to implement
it in PHP?






That is a question that came up recently in a PHP group on Linkedin. I
thought
it might also be worth discussing here, too.

Some years ago I became acquainted with a rather robust system for
managing
credit unions where the entire UI was implemented through a single command
line
prompt, like a Unix or DOS shell. Quite literally, the only two events
that the
server would respond to were the Enter and Escape keys. Interaction with
the
server would begin by entering a short action code, which would generally
trigger a dialog to enter data into a database, perform transactions, and
so
forth, one input line at a time.

Perhaps surprisingly, users liked it, and became productive with it, but
contrast that type of UI with an HTML page that may be filled with any
number of
visual and input capable elements simultaneously, and using
element.addEventListener() or element.attachEvent() to register a
potentially
broad range of keyboard and mouse event handlers for any number UI element

displayed.

I suppose you could carry the comparison (contrast) even further by using
AJAX
to subscribe to a network service which may be "listening" for events on a

network, and notify each client of it. A good use case might be a
moderated chat
service. It might be helpful to update each user's screen whenever a
participant
on the network enters or leaves the chat service. Maybe you want their
name
begin flashing when they begin typing. Every client should be notified the

moment any one of them enters a new message.

I'm not sure how to implement something that in PHP. I assume it can be
done
because Facebook chat works something like that. Using a tool like
Fiddler, you
can see the browser performing an asynchronous request that waits for up
to
something like 2 minutes, for the server respond. I assume the server in
turn is
waiting on a queue of sorts. But I'm not aware of the implementation
details on
the server, beyond configuring the HTTP server to allow persistent
connections.


Contrast network listening, vs network polling. Polling from the client
at
regular intervals consumes more bandwidth and other resources, and yet is
not
quite as responsive as listening on a queue.

-Nathan





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.