11 protected $starttime = 0;
14 protected $interval = 1;
15 protected $timeInterval = 0;
16 protected $prevLineLen = 0;
17 protected $prevLineTime = 0;
18 protected $isInteractive =
true;
19 protected $updateProcessTitle =
false;
24 if (function_exists(
'posix_isatty')) {
25 $this->setInteractive(posix_isatty(STDOUT));
45 $interval = (int)$interval;
47 $this->timeInterval = 0;
48 $this->interval = $interval;
55 $interval = (int)$interval;
57 $this->timeInterval = $interval;
65 $this->isInteractive = ($bool ===
true);
71 $this->updateProcessTitle =
$prefix;
79 $this->progress = $at;
83 $this->starttime = microtime(
true);
84 return $this->progress(0);
88 if ($this->progress < $this->max) {
89 $this->progress($this->max);
91 if ($this->isInteractive) {
102 if ($p == $this->max) {
105 if ($this->interval > 0 && ($p % $this->interval == 0)) {
108 if ($this->timeInterval > 0 && ((microtime(
true) - $this->prevLineTime) > $this->timeInterval)) {
119 if ($this->isTimeToUpdateProgress($p)) {
120 $ratio = (($this->max == 0) ? 0 : $p / $this->max);
121 $line = sprintf(
"%s%3d%% (%d/%d) [elapsed: %d sec. | remaining: %d sec. | ETA: %s]", ($this->prefix !=
'' ? $this->prefix .
' ' :
'') , intval(100 *
$ratio) , $p, $this->max, (microtime(
true) - $this->starttime) , $this->eta($p,
false) , $this->eta($p));
122 if ($this->isInteractive) {
124 if (strlen($line) < $this->prevLineLen) {
125 print str_repeat(
" ", $this->prevLineLen - strlen($line));
130 $this->updateProcessTitle($line);
131 $this->prevLineLen = strlen($line);
132 $this->prevLineTime = microtime(
true);
134 $this->progress = $p;
138 protected function eta($done, $eta =
true)
140 $now = microtime(
true);
141 $rate = ($now - $this->starttime) / $done;
142 $remainingtime = ($this->max - $done) * $rate;
144 return date(DATE_RFC2822, $now + $remainingtime);
146 return $remainingtime;
150 if (!function_exists(
'cli_set_process_title')) {
153 return ($this->updateProcessTitle !==
false && $this->updateProcessTitle !=
'');
155 private function updateProcessTitle($suffix =
'')
157 if ($this->isProcessTitleEnabled()) {
158 $title = $this->updateProcessTitle;
162 cli_set_process_title(
$title);
setUpdateProcessTitle($prefix)
setTimeInterval($interval)
if(!is_string($famid)) $progress
isTimeToUpdateProgress($p)