]> git.openstreetmap.org Git - nominatim.git/blob - utils/warm.php
Script to automatically warm the postgresql query before sending traffic
[nominatim.git] / utils / warm.php
1 #!/usr/bin/php -Cq
2 <?php
3
4         require_once(dirname(dirname(__FILE__)).'/lib/init-cmd.php');
5         ini_set('memory_limit', '800M');
6
7         $aCMDOptions = array(
8                 "Tools to warm nominatim db",
9                 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
10                 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
11                 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
12                 array('reverse-only', '', 0, 1, 0, 0, 'bool', 'Warm reverse only'),
13                 array('search-only', '', 0, 1, 0, 0, 'bool', 'Warm reverse only'),
14         );
15         getCmdOpt($_SERVER['argv'], $aCMDOptions, $aResult, true, true);
16
17         require_once(CONST_BasePath.'/lib/log.php');
18         require_once(CONST_BasePath.'/lib/Geocode.php');
19         require_once(CONST_BasePath.'/lib/PlaceLookup.php');
20         require_once(CONST_BasePath.'/lib/ReverseGeocode.php');
21
22         $oDB =& getDB();
23
24         $bVerbose = $aResult['verbose'];
25
26         if (!$aResult['search-only']) {
27
28                 $oReverseGeocode = new ReverseGeocode($oDB);
29                 $oReverseGeocode->setIncludeAddressDetails(true);
30
31                 echo "Warm reverse: ";
32                 if ($bVerbose) echo "\n";
33                 for($i = 0; $i < 1000; $i++) {
34                         $fLat = rand(-9000, 9000) / 100;
35                         $fLon = rand(-18000, 18000) / 100;
36                         if ($bVerbose) echo "$fLat, $fLon = ";
37                         $oReverseGeocode->setLanguagePreference(array('en'));
38                         $oReverseGeocode->setLatLon($fLat, $fLon);
39                         $oReverseGeocode->setZoom(20);
40                         $aDetails = $oReverseGeocode->lookup();
41                         if ($bVerbose) echo $aDetails['langaddress']."\n";
42                         else echo ".";
43                 }
44                 echo "\n";
45         }
46
47         if (!$aResult['reverse-only']) {
48
49                 $oGeocode =& new Geocode($oDB);
50
51                 echo "Warm search: ";
52                 if ($bVerbose) echo "\n";
53                 $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000';
54                 foreach($oDB->getCol($sSQL) as $sWord) {
55                         if ($bVerbose) echo "$sWord = ";
56                         $oGeocode->setLanguagePreference(array('en'));
57                         $oGeocode->setQuery($sWord);
58                         $aSearchResults = $oGeocode->lookup();
59                         if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n";
60                         else echo ".";
61                 }
62         }
63