On Fri, Jun 1, 2012 at 3:45 PM, rene7705 <rene7...@gmail.com> wrote: > Hi.. > > I've got several scripts now that may run for a long time; the > self-test script for my htmlMicroscope, my serviceLog component when > it calculates totals for a large number of hits, a curl script that is > likely to one day crawl a hundred or so RSS urls in a single update, > etc, etc.
I don't see how these scripts would need more than the default 30 seconds execution time, except for the crawler maybe. But you want the crawler to be a cronjob anyway. > > I'd like to build a generic system (and opensource it) to allow PHP to > execute a long running script, and somehow get a progress bar with > "what am I doing now"-status-msg for such processes, in the browser. > > The easiest thing, and maybe the only way this will work, is to load > up a site's framework html (so as to display the site), then call the > long-running script via ajax. > However, a long-running script needs set_time_limit(0), which is > something shared hosters just won't do for browsers. > A moderately good shared hoster will however allow you to > set_time_limit(0) for PHP cron jobs. I guess you're on a old fashioned safe mode host? Never had any problems using set_time_limit on web scripts on my previous shared hosters (got private servers now). > > So I'd need to build a cron PHP daemon that listens for new tasks. > That won't be much of a problem, I've done it before. > > But the task definition itself puzzles me a lot still. > I suppose I'd need an ID for the task/job, and include in the task def > what worker-php-script and worker-php-function to call, with also the > parameters for the worker function. > The worker function would then call back certain daemon functions to > push status updates to the browser. I wonder how you're planning on doing that. Since shared hosts have either safe mode on, or at least disabled the system call, you cannot call the php binary. I guess there are two options: 1) Include all possible worker scripts that you're are going to use, and call the worker function. 2) Load the file and call eval on it. Note that in both cases, the script still runs inside the cronjob daemon, and the daemon will not be able to handle other task. You would need to fork, but I doubt the PCNTL functions are available on your shared host.. For the task definition, I think I would choose a set of defines to give each task a unique ID. Set up a task table with ID, class/function. Then define this function with a abstract header with just one parameter, $data, and have each task interpret this data as it wishes. > > And the browser can then just kick off the task, and poll every 5 > seconds or so for very brief status updates in JSON format. Database, sockets? > > This is how I can import videos of any length into my CMS, and convert > them to flash video aswell (even optionally converting on another, > dedicated server). You're probably limited to the upload size limits. These are usually very tight at shared hosting... > > Once again I'm asking you all for input and tips before I begin on > this new workDaemon component of mine.. > > I suppose most of you'd want a neat PHP object of it? Not my usual > procedural-only PHP coding? I wouldn't mind a simple while(true) procedural daemon, though the tasks are probably best defined as classes. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php