We don't quite know what you need, but I want to offer up this for an example of pseudo realtime. You can use this to emulate multi-threaded stuff in web applications.
I have a script like this set up to run on init after everything else. I even use start-stop-daemon to keep an eye on it.
<?php
/** eventd.php -- Event Daemon */
set_time_limit(0);
error_reporting(E_ALL);
if (!substr(SAPI_NAME, 0, 3) == 'cli')
{
die('You must run this from the command line!');
}
$counter = time();
while (true)
{
// Sleeps are good for the processor
sleep(1);
// Don't call time() every second.
$counter += 1;
if ($counter % 2 == 0)
{
// $counter is an *even* number...
// DO SOMETHING HERE
}
else
{
// $counter is an *odd* number...
// DO SOMETHING HERE
}
if ($counter % 60 == 0)
{
// Counter is a multiple of 60. Resync
// the timer so we don't get too far off
$counter = time();
}
} // main loop
?>
If you don't want to run it every second, then increase the sleep statement. Note, however, if you are running stuff only once a minute or slower, cron may be a better idea (as dougal85 said).
This technique uses very little cpu time and memory on my debian box, even at 20 requests per second on the web side.
Have your web process send raw data to a mysql heap table or other fast storage. Then set up this script to read from it and do all the hard work. Only let it do a couple things each pass (hence why I broke it up to even and odd). Make sure the code is error free as possible (try/catch!) and set it free.
tail -f php_errors.log & pray --faithfully