up
This commit is contained in:
@@ -231,11 +231,15 @@ class MediaService {
|
||||
}
|
||||
|
||||
$tmpFile = tempnam(sys_get_temp_dir(), 'wget_');
|
||||
// Solo pasar Authorization header para evitar problemas con User-Agent personalizado en CDN
|
||||
$headerArgs = '';
|
||||
foreach ($headers as $h) {
|
||||
$headerArgs .= ' --header=' . escapeshellarg($h);
|
||||
if (stripos($h, 'Authorization:') === 0) {
|
||||
$headerArgs .= ' --header=' . escapeshellarg($h);
|
||||
}
|
||||
}
|
||||
$cmd = 'wget -q --prefer-family=IPv4 -O ' . escapeshellarg($tmpFile) . $headerArgs . ' ' . escapeshellarg($url) . ' 2>&1';
|
||||
// --tries=5: reintenta automáticamente ante Connection reset by peer (problema con lookaside.fbsbx.com)
|
||||
$cmd = 'wget --tries=5 --prefer-family=IPv4 -O ' . escapeshellarg($tmpFile) . $headerArgs . ' ' . escapeshellarg($url) . ' 2>&1';
|
||||
try {
|
||||
exec($cmd, $output, $exitCode);
|
||||
} catch (\Error $e) {
|
||||
@@ -244,14 +248,17 @@ class MediaService {
|
||||
return $this->procOpenDownload($url, $headers);
|
||||
}
|
||||
|
||||
if ($exitCode === 0 && file_exists($tmpFile) && filesize($tmpFile) > 0) {
|
||||
$fileSize = (file_exists($tmpFile) ? filesize($tmpFile) : 0);
|
||||
error_log("[MediaService::shellDownload] wget exit={$exitCode} size={$fileSize} output=" . implode(' | ', array_slice($output, -3)));
|
||||
|
||||
if ($exitCode === 0 && $fileSize > 0) {
|
||||
$content = file_get_contents($tmpFile);
|
||||
unlink($tmpFile);
|
||||
error_log("[MediaService::shellDownload] wget OK, " . strlen($content) . " bytes");
|
||||
return $content;
|
||||
}
|
||||
|
||||
error_log("[MediaService::shellDownload] wget FAIL exit={$exitCode}");
|
||||
error_log("[MediaService::shellDownload] wget FAIL exit={$exitCode} size={$fileSize}");
|
||||
if (file_exists($tmpFile)) unlink($tmpFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user