Re: Re: Periodic Actions in PHP?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On Jun 13, 2009, at 9:11, Colin Guthrie <gmane@xxxxxxxxxxxxxx> wrote:

'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 is needed.


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 you'd have a javascript timeout that submits an ajax request to the 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.

Col

--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
 Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
 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


If the goal was to push data, the OP could investigate the use of a comet server. It holds a long running stream allowing the server to push new data to the client.

Bastien

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux