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