entityManager->getRepository(Download::class)->find($downloadId); $downloadEntity->setProgress(0); $this->entityManager->flush(); $process = new Process([ '/bin/sh', '/var/www/bash/app/wget_download.sh', $baseDir, $title, $url ]); $process->setTimeout(1800); // 30 min $process->setIdleTimeout(600); // 10 min $process->start(); try { $progress = 0; $this->entityManager->flush(); $process->wait(function ($type, $buffer) use ($progress, $downloadEntity): void { if (Process::ERR === $type) { $pregMatchOutput = []; preg_match('/[\d]+%/', $buffer, $pregMatchOutput); if (!empty($pregMatchOutput)) { if ($pregMatchOutput[0] !== $progress) { $progress = (int) $pregMatchOutput[0]; $downloadEntity->setProgress($progress); $this->entityManager->flush(); } } } fwrite(STDOUT, $buffer); }); $downloadEntity->setProgress(100); } catch (ProcessFailedException $exception) { $downloadEntity->setStatus('Failed'); } $this->entityManager->flush(); } }