]> git.openstreetmap.org Git - nominatim.git/blob - utils/server_compare.php
f44b073eb2d847dc831c2628ebee844301265e27
[nominatim.git] / utils / server_compare.php
1 <?php
2
3 $sFile = 'sample.log.txt'; // Apache log file
4 $sHost1 = 'http://mq-open-search-lm02.ihost.aol.com:8000/nominatim/v1';
5 $sHost2 = 'http://mq-open-search-lm03.ihost.aol.com:8000/nominatim/v1';
6
7
8 $sHost1Escaped = str_replace('/', '\\/', $sHost1);
9 $sHost2Escaped = str_replace('/', '\\/', $sHost2);
10
11 $aToDo = array(251, 293, 328, 399.1, 455.1, 479, 496, 499, 574, 609, 702, 790, 846, 865, 878, 894, 902, 961, 980);
12
13 $hFile = @fopen($sFile, 'r');
14 if (!$hFile) {
15     echo "Unable to open file: $sFile\n";
16     exit;
17 }
18
19 $i = 0;
20 while (($sLine = fgets($hFile, 10000)) !== false) {
21     $i++;
22     if (!in_array($i, $aToDo)) continue;
23
24     if (preg_match('#"GET (.*) HTTP/1.[01]"#', $sLine, $aResult)) {
25         $sURL1 = $sHost1.$aResult[1];
26         $sURL2 = $sHost2.$aResult[1];
27
28         $sRes1 = '';
29         $k = 0;
30         while (!$sRes1 && $k < 10) {
31             $sRes1 = file_get_contents($sURL1);
32             $k++;
33             if (!$sRes1) sleep(10);
34         }
35         $sRes2 = file_get_contents($sURL2);
36
37         // Strip out the things that will always change
38         $sRes1 =  preg_replace('# timestamp=\'[^\']*\'#', '', $sRes1);
39         $sRes1 =  str_replace($sHost1, '', $sRes1);
40         $sRes1 =  str_replace($sHost1Escaped, '', $sRes1);
41         $sRes2 =  preg_replace('# timestamp=\'[^\']*\'#', '', $sRes2);
42         $sRes2 =  str_replace($sHost2, '', $sRes2);
43         $sRes2 =  str_replace($sHost2Escaped, '', $sRes2);
44
45         if ($sRes1 != $sRes2) {
46             echo "$i:\n";
47             var_dump($sURL1, $sURL2);
48
49             $sRes = $sURL1.":\n";
50             for ($j = 0; $j < strlen($sRes1); $j+=40) {
51                 $sRes .= substr($sRes1, $j, 40)."\n";
52             }
53             file_put_contents('log/'.$i.'.1', $sRes);
54
55             $sRes = $sURL2.":\n";
56             for ($j = 0; $j < strlen($sRes2); $j+=40) {
57                 $sRes .= substr($sRes2, $j, 40)."\n";
58             }
59             file_put_contents('log/'.$i.'.2', $sRes);
60         }
61         echo ".\n";
62     } else {
63         var_dump($sLine);
64     }
65 }
66
67 fclose($hFile);