*/ header('Content-Type: application/json; charset=utf-8'); header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, OPTIONS'); header('Access-Control-Allow-Headers: Content-Type'); if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit(); } define('SNAP_DIR', __DIR__ . '/cache/bh-raw/'); $VALID = ['products', 'warehouses', 'inventory']; $kind = $_GET['kind'] ?? ''; $wid = $_GET['id'] ?? ''; if (!in_array($kind, $VALID, true) || ($kind === 'inventory' && !preg_match('/^[A-F0-9]{32}$/i', $wid))) { http_response_code(400); echo json_encode(['resultCode' => 0, 'errorText' => 'gecersiz kind/id parametresi', 'data' => null]); exit; } $file = SNAP_DIR . ($kind === 'inventory' ? "inventory_{$wid}.json" : "{$kind}.json"); if (!file_exists($file)) { http_response_code(503); header('X-Cache: no-snapshot'); echo json_encode(['resultCode' => 0, 'errorText' => 'snapshot henuz yok (collector bekleniyor)', 'data' => null]); exit; } $age = time() - filemtime($file); // Bayatlik tetigi: snapshot 70dk'dan eskiyse toplayiciyi YEREL olarak durt. // Bu istek BizimHesap'a degil ayni sunucudaki bh-collector.php'ye gider; // collector kendini kisitlar (50dk tazelik + flock + 429 devre kesici). // 200ms'de koparilir — collector ignore_user_abort ile calismaya devam eder. // Boylece tetikleme HF Space'e muhtac degil: sistemi kullanan herkes canli tutar. if ($age > 4200) { $ch = curl_init('https://video.trek-turkey.com/bh-collector.php?key=trkbh2026x'); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT_MS => 200, CURLOPT_NOSIGNAL => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, ]); @curl_exec($ch); curl_close($ch); } header('X-Cache: snapshot'); header('X-Snapshot-Age: ' . $age); readfile($file);