// Mejorar rendimiento y seguridad ini_set('zlib.output_compression', 1); ini_set('memory_limit', '256M'); // =========================== // LOG DE ERRORES CENTRALIZADO // =========================== function log_error($mensaje) { error_log(date('Y-m-d H:i:s') . ' - ' . $mensaje . "\n", 3, __DIR__ . '/../logs/error.log'); } // =========================== // VALIDACIÓN DE INPUTS GLOBAL // =========================== function validar_input_global($dato) { if (is_array($dato)) { return array_map('validar_input_global', $dato); } return htmlspecialchars(trim($dato), ENT_QUOTES | ENT_HTML5, 'UTF-8'); } // =========================== // USO DE CACHE EN CONSULTAS FRECUENTES // =========================== function consulta_cacheada($pdo, $query, $params = [], $cacheTime = 600) { $cacheKey = md5($query . serialize($params)); $cacheFile = __DIR__ . '/../logs/cache_' . $cacheKey . '.json'; if (file_exists($cacheFile) && (time() - filemtime($cacheFile)) < $cacheTime) { return json_decode(file_get_contents($cacheFile), true); } $stmt = $pdo->prepare($query); $stmt->execute($params); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); file_put_contents($cacheFile, json_encode($result)); return $result; }
Para continuar usando MendozaDirectorio.com, debés aceptar nuestros Términos y Condiciones y nuestra Política de Privacidad.