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