From: Richard L. <ce...@l-...> - 2006-11-14 18:25:52
|
fork/exec/sleep is rife with shoals for the newbie, so test thoroughly if you go that route. As far as the program execution time exceeding the interval of a cron job goes, one easy thing to do is to have a mkdir() [which is guaranteed atomic] something like this: <?php $lock_file = "/var/run/thisscriptname.lock"; $lock_stale = 60 * 5; // 5 minutes, for example if (file_exists($lock_file)){ if (filemtime($lock_file) < time() - $lock_stale)){ error_log("Removing stale lock: $lock_file"); unlink($lock_file); } else{ error_log("Aborting run due to lock: $lock_file"); exit; } } mkdir($lock_file); while ( ... ){ //process your records or whatever, and do this a LOT: touch($lock_file); } ?> Damn! touch() on a dir in Windows is broken?! Sheesh. You're on your own for Windows, kid... Sorry. http://php.net/touch On Tue, November 14, 2006 8:08 am, Jason Rexilius wrote: > A job queue in the DB and a cron job that reads the DB and executes it > is the best way probably. > > If you did not have access to cron on your system, another way would > be > to use fork/exec and have the child job sleep for 5 minutes and then > check the state of a flat file or DB for cancellation. > > > Hank Marquardt wrote: >> Ohhh, one gotcha. Never set your interval shorter than the time >> the >> job takes to run ... bad things happen :) >> >> On 11/13/06, *Hank Marquardt* < hma...@gm... >> <mailto:hma...@gm...>> wrote: >> >> cron job. put a time stamp in the database, cron job checks >> the >> timestamp and executes all records > 5 minutes ... if you >> execute >> the cronjob every 5 minutes then the longest one would sit is >> 9:59 >> ... shorten the interval, shorten the length ... >> >> Could do the same thing with timestamps on files if you don't >> want >> to do the database thing. >> >> >> >> On 11/13/06, * Terry* < ma...@ao... >> <mailto:ma...@ao...>> wrote: >> >> >> How can I run a script 5 min after a user does something? >> >> I want to give a user 5 minutes to cancel an action, and if >> they >> don't >> then it actually happens. So, I'd like to run a script 5 >> minutes >> later, >> and have it perform any actions in the queue that are 5+ >> minutes >> old. 5 >> min is not critical, but I don't think I should wait longer >> than 10 >> min. >> >> What if it's only needed very infrequently? >> >> I'm thinking the options are to use a cron job that runs >> every few >> minutes, or, call the script with curl and have it sleep for >> 5 >> minutes >> first. >> >> Terry >> >> >> ------------------------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web >> services, >> security? >> Get stuff done quickly with pre-integrated technology to >> make >> your job easier >> Download IBM WebSphere Application Server v.1.0.1 based on >> Apache Geronimo >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >> <http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642> >> _______________________________________________ >> chiPHPug-discuss mailing list >> chi...@li... >> <mailto:chi...@li...> >> https://lists.sourceforge.net/lists/listinfo/chiphpug-discuss >> >> >> >> >> ------------------------------------------------------------------------ >> >> ------------------------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web services, >> security? >> Get stuff done quickly with pre-integrated technology to make your >> job easier >> Download IBM WebSphere Application Server v.1.0.1 based on Apache >> Geronimo >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >> >> >> ------------------------------------------------------------------------ >> >> _______________________________________________ >> chiPHPug-discuss mailing list >> chi...@li... >> https://lists.sourceforge.net/lists/listinfo/chiphpug-discuss > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > chiPHPug-discuss mailing list > chi...@li... > https://lists.sourceforge.net/lists/listinfo/chiphpug-discuss > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? |