I have a web application that gathers data from the user. Data is gathered via multiple asynchronous requests, so every time new data is retrieved it is immediately sent to the server because I can't know when the user will quit the webpage and I need to process data if even if it is missing.I need to receive these chunks of information, and trigger the processing scripts when no data is retrieved for 30 seconds, without using daemons, system calls or cron jobs. (I'd be happy if you suggest other approaches fulfilling these requirements.)<?php/** * What you see here, is one of the worst things you'll ever see.. * It's almost physically painful just thinking of the concept of this file.. * Feels like pooping glass again.. * Feels like a mad C++ developer.. * Which way did you say Feelodelphia was anyway ? * ** * Father, I know that I have broken your laws and my sins have separated me from you. * I am truly sorry, and now I want to turn away from my past sinful life toward you. * Please forgive me, and help me avoid sinning again. * * Some people actually reached enlightenment because of this... **//** * This is kind of a daemon, that is run only once, and acts like a cron to process * prints, in a reasonable delay of time. * Previous implementation (a daemon per client) would have eaten 2MB per client * of memory, which is a whack. **/include ../helperMethods.php;include daemonconfig.php;ini_set('max_execution_time', 0);ignore_user_abort(true);if (file_exists($runningMarkerFile)) {    die(daemon already running);}if (filemtime($runningMarkerFile) - time() > $daemonTimeout) {    unlink($runningMarkerFile);}touch($runningMarkerFile);while (true) {    set_time_limit($daemonTimeout);    $queuedItems = file($queueFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES | LOCK_EX);    foreach ($queuedItems as $item) {        $filePath = $tempPrintsPath . $item;         // If file has been saved 30 seconds ago, process it, if not, wait until next iteration        if (filemtime($filePath) - time() < 30) continue;        // Check if the file has been marked as final.        // TODO        lock_replace_in_file($queueFile, $item, );        $jPrint = unserialize($filePath);        include ../resultPrintHandler.php;    }    sleep(5);}unlink($runningMarkerFile);I have the following questions on it:Can it reliably run on shared hosting? I know shared hosting caps execution time, the script shouldn't hit it anyway.Should I add timeout logic?
PHP daemon like behavior hack
php