'Twas brillig, and Parham Doustdar at 13/06/09 09:42 did gyre and gimble:
Hi there, I'm going to create a small chat script with PHP. The
messages you want others to see will be added to a flat file (I.E.
TXT file), and read and displayed by PHP. However, I want this
reading and displaying to be periodic. This means that I want PHP to
check the file for new lines every,say, fifteen seconds. How may I do
that? I have been unable to find any function that acts like a timer.
For handling periodic tasks in a web environement, I use a little
persistent object (stored using APC) that has it's "process()" method
called on every request. Internally it knows when it was last run and
will actually only do work in it's process() method if it's not been
called for a while.
When this work is done, the user's request is obviously slowed down
slightly, but not in a noticeable way.
If you don't need something this self contained, then a normal cron job
All that asside, I'm not sure you're asking the right question. If
you've got a chat system, then the client side is presumable a web
server. You can't really push information from the server side to the
client, so you really need to pull it from the client side. Usually
server and displays any new messages to the user. In this case, PHP
doesn't need to be timed, the client is pulling periodically so it's the
client that sets the timer.
Tribalogic Limited [http://www.tribalogic.net/]
Mandriva Linux Contributor [http://www.mandriva.com/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php