38 lines
1.4 KiB
PHP
38 lines
1.4 KiB
PHP
<?php
|
|
/* V144: cache 1h for ambre-deps-find - previous version took 30+s for find / */
|
|
header("Content-Type: application/json");
|
|
|
|
$cache_file = "/tmp/ambre-deps-cache.json";
|
|
$cache_ttl = 3600; /* 1 hour */
|
|
|
|
if (file_exists($cache_file) && (time() - filemtime($cache_file)) < $cache_ttl) {
|
|
/* V144 cache HIT: respond instantly from cache */
|
|
$cached = @file_get_contents($cache_file);
|
|
if ($cached) {
|
|
header("X-V144-Cache: HIT");
|
|
echo $cached;
|
|
exit;
|
|
}
|
|
}
|
|
|
|
/* V144 cache MISS: scan limited paths only (not full /) */
|
|
$out = [];
|
|
$out["rembg_find"] = trim(@shell_exec("find /usr/local/bin /usr/bin /opt/venv -name rembg -type f -executable 2>/dev/null | head -3") ?: "");
|
|
$out["python_path"] = trim(@shell_exec("python3 -c \"import sys; print(sys.executable)\"") ?: "");
|
|
|
|
/* Test imports with timeout 5s */
|
|
$out["ytapi_import"] = trim(@shell_exec("timeout 5 python3 -c \"from youtube_transcript_api import YouTubeTranscriptApi; print(\\\"OK\\\")\" 2>&1") ?: "");
|
|
$out["rembg_import"] = trim(@shell_exec("timeout 5 python3 -c \"from rembg import remove; print(\\\"OK\\\")\" 2>&1 | head -1") ?: "");
|
|
|
|
$out["_v144_cached_at"] = date("c");
|
|
$out["_v144_cache_ttl_sec"] = $cache_ttl;
|
|
|
|
$response = json_encode($out, JSON_PRETTY_PRINT);
|
|
|
|
/* Save cache */
|
|
@file_put_contents($cache_file, $response);
|
|
@chmod($cache_file, 0644);
|
|
|
|
header("X-V144-Cache: MISS");
|
|
echo $response;
|