PluginProbe
ManageWP Worker / 4.9.29
ManageWP Worker v4.9.29
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / Progress / Upload.php

Upload.php in ManageWP Worker 4.9.29, at src/MWP/Progress/Upload.php

70 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <contact@managewp.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_Progress_Upload extends MWP_Progress_Abstract
12 {
13 /**
14 * @var int
15 */
16 private $fileSize;
17
18 /**
19 * @var Monolog_Psr_LoggerInterface
20 */
21 private $logger;
22
23 /**
24 * @var int
25 */
26 private $lastProgress = 0;
27
28 public function __construct($fileSize, $threshold, Monolog_Psr_LoggerInterface $logger)
29 {
30 $this->fileSize = $fileSize;
31 $this->setThreshold($threshold);
32 $this->logger = $logger;
33 }
34
35 public function callback(&$curl, $downloadSize, $downloadedSize, $uploadSize, $uploadedSize = 0)
36 {
37 if (!$this->yieldCallback()) {
38 return;
39 }
40
41 if (func_num_args() < 5) {
42 $uploadedSize = $uploadSize;
43 $uploadSize = $downloadedSize;
44 $downloadedSize = $downloadSize;
45 $downloadSize = $curl;
46 }
47
48 $offset = is_resource($curl) ? $this->calculateOffset($curl) : 0;
49 $currentProgress = $uploadedSize + $offset;
50 $speed = $this->formatBytes(($currentProgress - $this->lastProgress) / $this->getThreshold());
51 $this->lastProgress = $currentProgress;
52
53 $progress = round($currentProgress / $this->fileSize * 100, 2);
54
55 global $forkedRequest;
56 if (!$forkedRequest) {
57 echo " ";
58 flush();
59 }
60
61 $this->logger->info(
62 'Upload progress: {progress}% (speed: {speed}/s)',
63 array(
64 'progress' => $progress,
65 'speed' => $speed,
66 )
67 );
68 }
69 }
70