3 * SPDX-License-Identifier: GPL-2.0-only
5 * This file is part of Nominatim. (https://nominatim.org)
7 * Copyright (C) 2022 by the Nominatim developer community.
8 * For a full list of authors see the git log.
12 function logStart(&$oDB, $sType = '', $sQuery = '', $aLanguageList = array())
14 $fStartTime = microtime(true);
15 $aStartTime = explode('.', $fStartTime);
16 if (!isset($aStartTime[1])) {
21 if (isset($_GET['format'])) {
22 $sOutputFormat = $_GET['format'];
25 if ($sType == 'reverse') {
26 $sOutQuery = (isset($_GET['lat'])?$_GET['lat']:'').'/';
27 if (isset($_GET['lon'])) {
28 $sOutQuery .= $_GET['lon'];
30 if (isset($_GET['zoom'])) {
31 $sOutQuery .= '/'.$_GET['zoom'];
38 date('Y-m-d H:i:s', $aStartTime[0]).'.'.$aStartTime[1],
39 $_SERVER['REMOTE_ADDR'],
40 $_SERVER['QUERY_STRING'],
47 if (isset($_GET['email'])) {
48 $sUserAgent = $_GET['email'];
49 } elseif (isset($_SERVER['HTTP_REFERER'])) {
50 $sUserAgent = $_SERVER['HTTP_REFERER'];
51 } elseif (isset($_SERVER['HTTP_USER_AGENT'])) {
52 $sUserAgent = $_SERVER['HTTP_USER_AGENT'];
56 $sSQL = 'insert into new_query_log (type,starttime,query,ipaddress,useragent,language,format,searchterm)';
58 $sSQL .= join(',', $oDB->getDBQuotedList(array(
64 join(',', $aLanguageList),
75 function logEnd(&$oDB, $hLog, $iNumResults)
77 $fEndTime = microtime(true);
80 $aEndTime = explode('.', $fEndTime);
81 if (!isset($aEndTime[1])) {
84 $sEndTime = date('Y-m-d H:i:s', $aEndTime[0]).'.'.$aEndTime[1];
86 $sSQL = 'update new_query_log set endtime = '.$oDB->getDBQuoted($sEndTime).', results = '.$iNumResults;
87 $sSQL .= ' where starttime = '.$oDB->getDBQuoted($hLog[0]);
88 $sSQL .= ' and ipaddress = '.$oDB->getDBQuoted($hLog[1]);
89 $sSQL .= ' and query = '.$oDB->getDBQuoted($hLog[2]);
95 "[%s] %.4f %d %s \"%s\"\n",
102 file_put_contents(CONST_Log_File, $aOutdata, FILE_APPEND | LOCK_EX);