From edc5733715a65158919c1abc4d765b754f5dc659 Mon Sep 17 00:00:00 2001 From: Brian Quinion Date: Thu, 6 Feb 2014 16:50:41 +0000 Subject: [PATCH] Script to automatically warm the postgresql query before sending traffic --- utils/warm.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 utils/warm.php diff --git a/utils/warm.php b/utils/warm.php new file mode 100755 index 00000000..923e2aba --- /dev/null +++ b/utils/warm.php @@ -0,0 +1,63 @@ +#!/usr/bin/php -Cq +setIncludeAddressDetails(true); + + echo "Warm reverse: "; + if ($bVerbose) echo "\n"; + for($i = 0; $i < 1000; $i++) { + $fLat = rand(-9000, 9000) / 100; + $fLon = rand(-18000, 18000) / 100; + if ($bVerbose) echo "$fLat, $fLon = "; + $oReverseGeocode->setLanguagePreference(array('en')); + $oReverseGeocode->setLatLon($fLat, $fLon); + $oReverseGeocode->setZoom(20); + $aDetails = $oReverseGeocode->lookup(); + if ($bVerbose) echo $aDetails['langaddress']."\n"; + else echo "."; + } + echo "\n"; + } + + if (!$aResult['reverse-only']) { + + $oGeocode =& new Geocode($oDB); + + echo "Warm search: "; + if ($bVerbose) echo "\n"; + $sSQL = 'select word from word where word is not null order by search_name_count desc limit 1000'; + foreach($oDB->getCol($sSQL) as $sWord) { + if ($bVerbose) echo "$sWord = "; + $oGeocode->setLanguagePreference(array('en')); + $oGeocode->setQuery($sWord); + $aSearchResults = $oGeocode->lookup(); + if ($bVerbose) echo $aSearchResults[0]['langaddress']."\n"; + else echo "."; + } + } + -- 2.39.5