0 && $connection_id !== $connection_filter) continue; $matched++; $config = isset($connection['config']) && is_array($connection['config']) ? $connection['config'] : array(); $state_dir = rtrim((string)($config['state_dir'] ?? ''), '/'); if ($state_dir === '') { fwrite(STDERR, "Warmup für Verbindung #{$connection_id} übersprungen: Connector-State-Verzeichnis fehlt.\n"); $result = 1; continue; } if ($mode === 'periodic') { $state_file = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'bratonien-webdav-warmup.connection-'.$connection_id.'.json'; if (is_file($state_file) && is_readable($state_file)) { $raw = @file_get_contents($state_file); $state = $raw !== false ? json_decode($raw, true) : null; if (is_array($state)) { $last = (int)($state['last_periodic_at'] ?? 0); $interval = max(1, (int)$settings['periodic_hours']) * 3600; if ($last > 0 && time() - $last < $interval) { $remaining = max(0, $interval - (time() - $last)); fwrite(STDOUT, "Periodische Warmup-Prüfung für Verbindung #{$connection_id} noch nicht fällig ({$remaining}s verbleibend).\n"); continue; } } } } if ($mode === 'sync') { if (!is_dir($state_dir) && !@mkdir($state_dir, 0750, true) && !is_dir($state_dir)) { fwrite(STDERR, "Warmup-Priorität für Verbindung #{$connection_id} konnte nicht signalisiert werden: State-Verzeichnis fehlt.\n"); $result = 1; continue; } $priority_file = $state_dir.'/webdav-cache-warmup-priority-sync'; $priority_payload = json_encode(array( 'connection_id'=>$connection_id, 'requested_at'=>time(), 'reason'=>'connector-sync-complete', ), JSON_UNESCAPED_SLASHES); if (!is_string($priority_payload) || @file_put_contents($priority_file, $priority_payload."\n", LOCK_EX) === false) { fwrite(STDERR, "Warmup-Priorität für Verbindung #{$connection_id} konnte nicht geschrieben werden.\n"); $result = 1; continue; } @chmod($priority_file, 0664); } // Der Guard hält webdav-sync.lock für den gesamten Worker-Lauf geteilt. // Dadurch kann der produktive Source-/Shadow-Tree während Download, Swap, // Piwigo-Aufruf und Restore nicht von einem Connector-Sync ersetzt werden. $base = escapeshellarg('/bin/bash').' '.escapeshellarg($guard).' '.escapeshellarg($state_dir) .' '.escapeshellarg(PHP_BINARY).' '.escapeshellarg($worker) .' --connection-id='.$connection_id .' --mode='.escapeshellarg($mode); if ($wait) { $output = array(); $exit = 1; @exec($base.' 2>&1', $output, $exit); foreach ($output as $line) fwrite(STDOUT, $line."\n"); if ($exit !== 0) $result = $exit; } else { $command = 'nohup '.$base.' >> '.escapeshellarg($log).' 2>&1 < /dev/null & echo $!'; $output = array(); $exit = 1; @exec($command, $output, $exit); $pid = isset($output[0]) ? (int)$output[0] : 0; if ($exit !== 0 || $pid <= 0) { fwrite(STDERR, "Warmup für Verbindung #{$connection_id} konnte nicht gestartet werden.\n"); $result = 1; continue; } $started++; fwrite(STDOUT, "Warmup {$mode} für Verbindung #{$connection_id} gestartet (PID {$pid}).\n"); } } if ($connection_filter > 0 && $matched === 0) { fwrite(STDERR, "WebDAV-Verbindung #{$connection_filter} wurde nicht als aktive Connector-Verbindung gefunden.\n"); exit(1); } if (!$wait) fwrite(STDOUT, "Gestartete Warmup-Prozesse: {$started}.\n"); exit($result);