Files
michaelschiemer/tests/debug/cache-debug.php
Michael Schiemer 55a330b223 Enable Discovery debug logging for production troubleshooting
- Add DISCOVERY_LOG_LEVEL=debug
- Add DISCOVERY_SHOW_PROGRESS=true
- Temporary changes for debugging InitializerProcessor fixes on production
2025-08-11 20:13:26 +02:00

120 lines
4.6 KiB
PHP

<?php
declare(strict_types=1);
// Debug the actual discovery caching issue
require_once '/var/www/html/vendor/autoload.php';
echo "🔍 Discovery Cache Debug\n";
echo "=======================\n\n";
use App\Framework\Cache\CacheInitializer;
use App\Framework\Core\PathProvider;
use App\Framework\DateTime\SystemClock;
use App\Framework\DI\DefaultContainer;
use App\Framework\Discovery\Cache\DiscoveryCacheIdentifiers;
use App\Framework\Discovery\DiscoveryServiceBootstrapper;
use App\Framework\Performance\EnhancedPerformanceCollector;
use App\Framework\Performance\HighResolutionClock;
use App\Framework\Performance\MemoryMonitor;
try {
// Minimal setup
$container = new DefaultContainer();
$pathProvider = new PathProvider('/var/www/html');
$clock = new SystemClock();
// Mock the performance collector properly
$highResClock = new HighResolutionClock();
$memoryMonitor = new MemoryMonitor();
$performanceCollector = new EnhancedPerformanceCollector($clock, $highResClock, $memoryMonitor, true);
$container->instance(PathProvider::class, $pathProvider);
$container->instance(SystemClock::class, $clock);
echo "1. Setting up cache...\n";
$cacheInitializer = new CacheInitializer($performanceCollector, $container);
$cache = $cacheInitializer();
$container->instance(\App\Framework\Cache\Cache::class, $cache);
echo " Cache type: " . get_class($cache) . "\n";
// Check what cache key would be generated
$defaultPaths = [$pathProvider->getSourcePath()];
$cacheKey = DiscoveryCacheIdentifiers::fullDiscoveryKey($defaultPaths);
echo "\n2. Discovery cache key info:\n";
echo " Source path: " . $pathProvider->getSourcePath() . "\n";
echo " Cache key: " . (string)$cacheKey . "\n";
// Check if cache already has this key
echo "\n3. Checking existing cache...\n";
$existingResult = $cache->get($cacheKey);
echo " Has key in cache: " . ($existingResult->has($cacheKey) ? 'YES' : 'NO') . "\n";
if ($existingResult->has($cacheKey)) {
$existingItem = $existingResult->get($cacheKey);
echo " Existing cache hit: " . ($existingItem->isHit ? 'YES' : 'NO') . "\n";
echo " Existing cache value type: " . gettype($existingItem->value) . "\n";
}
echo "\n4. Running discovery bootstrap (first time)...\n";
$bootstrapper = new DiscoveryServiceBootstrapper($container, $clock);
$startTime = microtime(true);
$registry = $bootstrapper->bootstrap();
$firstRunTime = (microtime(true) - $startTime) * 1000;
echo " First run time: " . number_format($firstRunTime, 2) . "ms\n";
echo " Registry empty: " . ($registry->isEmpty() ? 'YES' : 'NO') . "\n";
// Check cache after first run
echo "\n5. Checking cache after first run...\n";
$afterFirstResult = $cache->get($cacheKey);
echo " Has key after first run: " . ($afterFirstResult->has($cacheKey) ? 'YES' : 'NO') . "\n";
if ($afterFirstResult->has($cacheKey)) {
$afterFirstItem = $afterFirstResult->get($cacheKey);
echo " Cache hit after first run: " . ($afterFirstItem->isHit ? 'YES' : 'NO') . "\n";
echo " Cache value type after first run: " . gettype($afterFirstItem->value) . "\n";
if (is_array($afterFirstItem->value)) {
echo " Cache array size: " . count($afterFirstItem->value) . "\n";
}
}
echo "\n6. Running discovery bootstrap (second time)...\n";
$startTime = microtime(true);
$registry2 = $bootstrapper->bootstrap();
$secondRunTime = (microtime(true) - $startTime) * 1000;
echo " Second run time: " . number_format($secondRunTime, 2) . "ms\n";
echo " Registry2 empty: " . ($registry2->isEmpty() ? 'YES' : 'NO') . "\n";
// Performance comparison
echo "\n7. Performance analysis:\n";
echo " First run: " . number_format($firstRunTime, 2) . "ms\n";
echo " Second run: " . number_format($secondRunTime, 2) . "ms\n";
if ($secondRunTime < $firstRunTime) {
$improvement = (($firstRunTime - $secondRunTime) / $firstRunTime) * 100;
echo " Improvement: " . number_format($improvement, 1) . "%\n";
if ($improvement > 50) {
echo " ✅ Cache is working well!\n";
} else {
echo " ⚠️ Cache working but not optimal\n";
}
} else {
echo " ❌ Cache NOT working - second run was slower or same\n";
}
if ($secondRunTime > 500) {
echo "\n❌ PROBLEM: Second run > 500ms, cache not effective!\n";
}
} catch (\Throwable $e) {
echo "\n❌ Error: " . $e->getMessage() . "\n";
echo "File: " . $e->getFile() . ":" . $e->getLine() . "\n";
}