function indexSector($oDB, $aSector, $fMaxBlocking, $fMaxLoad) { $iNum = $aSector['count']; $iRank = $aSector['rank']; $fNumSteps = ceil(sqrt($iNum) / 10); $iNumSteps = $fNumSteps * $fNumSteps; if ($fNumSteps > 1) { $iStepNum = 1; echo "Spliting into " . $fNumSteps * $fNumSteps . " steps\n"; // Convert sector number back to lat lon $fLon = 500 - floor($aSector['geometry_index'] / 1000) - 0.5; $fLat = 500 - $aSector['geometry_index'] % 1000 - 0.5; $fStepSize = 1 / $fNumSteps; for ($fStepLat = $fLat; $fStepLat < $fLat + 1; $fStepLat += $fStepSize) { for ($fStepLon = $fLon; $fStepLon < $fLon + 1; $fStepLon += $fStepSize) { while (getBlockingProcesses() > $fMaxBlocking || getLoadAverage() > $fMaxLoad) { echo "System busy, pausing indexing...\n"; sleep(60); } $fStepLonTop = $fStepLon + $fStepSize; $fStepLatTop = $fStepLat + $fStepSize; echo " Step {$iStepNum} of {$iNumSteps}: ({$fStepLon},{$fStepLat},{$fStepLonTop},{$fStepLatTop})\n"; $sSQL = 'update placex set indexed = true where geometry_index(geometry,indexed,name) = ' . $aSector['geometry_index'] . ' and rank_search = ' . $iRank; $sSQL .= " and ST_Contains(ST_SetSRID(ST_MakeBox2D(ST_SetSRID(ST_POINT({$fStepLon},{$fStepLat}),4326),ST_SetSRID(ST_POINT({$fStepLonTop},{$fStepLatTop}),4326)),4326),geometry)"; if (PEAR::IsError($xError = $oDB->query($sSQL))) { var_dump($xError); exit; } $iStepNum++; } } } $sSQL = 'update placex set indexed = true where geometry_index(geometry,indexed,name) = ' . $aSector['geometry_index'] . ' and rank_search = ' . $iRank; if (PEAR::IsError($xError = $oDB->query($sSQL))) { var_dump($xError); exit; } $oDB->query($sSQL); }
<?php require_once dirname(dirname(__FILE__)) . '/lib/init-website.php'; require_once CONST_BasePath . '/lib/log.php'; if (strpos(CONST_BulkUserIPs, ',' . $_SERVER["REMOTE_ADDR"] . ',') !== false) { $fLoadAvg = getLoadAverage(); if ($fLoadAvg > 2) { sleep(60); } if ($fLoadAvg > 4) { sleep(120); } if ($fLoadAvg > 6) { echo "Bulk User: Temporary block due to high server load\n"; exit; } } $oDB =& getDB(); ini_set('memory_limit', '200M'); // Format for output $sOutputFormat = 'xml'; if (isset($_GET['format']) && ($_GET['format'] == 'xml' || $_GET['format'] == 'json' || $_GET['format'] == 'jsonv2')) { $sOutputFormat = $_GET['format']; } // Show address breakdown $bShowAddressDetails = true; if (isset($_GET['addressdetails'])) { $bShowAddressDetails = (bool) $_GET['addressdetails']; } // Prefered language $aLangPrefOrder = getPrefferedLangauges();
sleep(60); } $iNum = $aSector['count']; echo $aSector['geometry_index'] . ": {$iNum}, {$iTotalLeft} remaining (" . date('H:i:s') . ")\n"; $iTotalLeft -= $iNum; flush(); $fNumSteps = round(sqrt($iNum) / 20); if ($fNumSteps > 1) { echo "{$fNumSteps} steps\n"; // Convert sector number back to lat lon $fLon = 500 - floor($aSector['geometry_index'] / 1000) - 0.5; $fLat = 500 - $aSector['geometry_index'] % 1000 - 0.5; $fStepSize = 1 / $fNumSteps; for ($fStepLat = $fLat; $fStepLat < $fLat + 1; $fStepLat += $fStepSize) { for ($fStepLon = $fLon; $fStepLon < $fLon + 1; $fStepLon += $fStepSize) { while (getBlockingProcesses() > 3 || getLoadAverage() > 1.9) { echo "System busy, pausing indexing...\n"; sleep(60); } $fStepLonTop = $fStepLon + $fStepSize; $fStepLatTop = $fStepLat + $fStepSize; echo " Step: ({$fStepLon},{$fStepLat},{$fStepLonTop},{$fStepLatTop})\n"; $sSQL = 'update placex set indexed = true where geometry_index(geometry,indexed,name) = ' . $aSector['geometry_index'] . ' and rank_search = ' . $i; $sSQL .= " and ST_Contains(ST_SetSRID(ST_MakeBox2D(ST_SetSRID(ST_POINT({$fStepLon},{$fStepLat}),4326),ST_SetSRID(ST_POINT({$fStepLonTop},{$fStepLatTop}),4326)),4326),geometry)"; // var_Dump($sSQL); $oDB->query($sSQL); } } } $sSQL = 'update placex set indexed = true where geometry_index(geometry,indexed,name) = ' . $aSector['geometry_index'] . ' and rank_search = ' . $i; $oDB->query($sSQL);