'/home/geograph', //base installation dir 'config'=>'www.geograph.org.uk', //effective config 'timeout'=>14, //timeout in minutes 'sleep'=>10, //sleep time in seconds 'load'=>100, //maximum load average 'help'=>0, //show script help? ); //very simple argument parser for($i=1; $i : base directory (/home/geograph) --config= : effective domain config (www.geograph.org.uk) --timeout= : maximum runtime of script (14) --sleep= : seconds to sleep if load average exceeded (10) --load= : maximum load average (100) --help : show this message --------------------------------------------------------------------- ENDHELP; exit; } //set up suitable environment ini_set('include_path', $param['dir'].'/libs/'); $_SERVER['DOCUMENT_ROOT'] = $param['dir'].'/public_html/'; $_SERVER['HTTP_HOST'] = $param['config']; //-------------------------------------------- // nothing below here should need changing require_once('geograph/global.inc.php'); require_once('geograph/gridimage.class.php'); require_once('geograph/gridsquare.class.php'); require_once('geograph/map.class.php'); require_once('geograph/image.inc.php'); $db = NewADOConnection($GLOBALS['DSN']); $start_time = time(); $end_time = $start_time + (60*$param['timeout']); #$map=new GeographMap; while (1) { $invalid_maps = $db->GetOne("select count(*) from mapcache where age > 0 and type_or_user >= -1"); if ($invalid_maps) { //done as many small select statements to allow new maps to be processed $recordSet = &$db->Execute("select * from mapcache where age > 0 and type_or_user >= -1 order by pixels_per_km desc, age desc limit 50"); while (!$recordSet->EOF) { //sleep until calm if we've specified a load average if ($param['load']<100) { while (get_loadavg() > $param['load']) { sleep($param['sleep']); if (time()>$end_time) exit; } } $map=new GeographMap; ## FIXME introduce $map->from_row($row); foreach($recordSet->fields as $name=>$value) { if (!is_numeric($name)) $map->$name=$value; } $map->mercator = !empty($map->mercator); if ($map->mercator) { $map->setScale($map->level); } $map->enableCaching(true, false); # FIXME better solution: build layers=2 at the beginning? $ok = $map->_renderMap(); echo (($ok?'re-rendered ':'FAILED: ').$map->getImageFilename()."\n"); flush(); if (time()>$end_time) { $recordSet->Close(); //well come to the end of the scripts useful life exit; } $recordSet->MoveNext(); } } else { //nothing more to do here exit; } //sleep anyway for a bit sleep($param['sleep']); if (time()>$end_time) { //retreat and let the next recruit take the strain exit; } } ?>