Last active
August 23, 2020 09:48
-
-
Save pborreli/5546547 to your computer and use it in GitHub Desktop.
Show progress of a file download inside Symfony 2.3 console #howto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
protected function execute(InputInterface $input, OutputInterface $output) | |
{ | |
$progress = $this->getHelperSet()->get('progress'); | |
$ctx = stream_context_create(array(), array('notification' => function ($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) use ($output, $progress) { | |
switch ($notification_code) { | |
case STREAM_NOTIFY_FILE_SIZE_IS: | |
$progress->start($output, $bytes_max); | |
break; | |
case STREAM_NOTIFY_PROGRESS: | |
$progress->setCurrent($bytes_transferred); | |
break; | |
} | |
})); | |
$file = file_get_contents($url, false, $ctx); | |
$progress->finish(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to change
$progress->start($output, $bytes_max);
to$progress->start($bytes_max);
on last symfony/console version though (2.6.4) .