$cat, 'id' => $id)); if ($row !== false && $row['dateline'] >= time()) { return $cache[$key] = $row['value']; } if (!$dnsQuery) return false; // Unknown, query $res = dns_get_record($host . '.pci.id.ucw.cz', DNS_TXT); if (!is_array($res)) return false; foreach ($res as $entry) { if (isset($entry['txt']) && substr($entry['txt'], 0, 2) === 'i=') { $string = substr($entry['txt'], 2); Database::exec('INSERT INTO pciid (category, id, value, dateline) VALUES (:cat, :id, :value, :timeout)' . ' ON DUPLICATE KEY UPDATE value = VALUES(value), dateline = VALUES(dateline)', array( 'cat' => $cat, 'id' => $id, 'value' => $string, 'timeout' => time() + mt_rand(10, 30) * 86400, ), true); return $cache[$key] = $string; } } return $cache[$key] = ($row['value'] ?? false); } }