X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=src%2Fpharext%2FTask%2FStreamFetch.php;h=029754ef773e906b7d9e57df012f511afc3d5ace;hb=3bab80c9541fce30bec2f69f41ad931ea4db7880;hp=3b1fc29cb53b4db1ce44ff6261e91444e3c591e8;hpb=337e76964be2ed6724633ac477affc3a28426c97;p=pharext%2Fpharext diff --git a/src/pharext/Task/StreamFetch.php b/src/pharext/Task/StreamFetch.php index 3b1fc29..029754e 100644 --- a/src/pharext/Task/StreamFetch.php +++ b/src/pharext/Task/StreamFetch.php @@ -33,16 +33,21 @@ class StreamFetch implements Task private function createStreamContext() { $progress = $this->progress; - return stream_context_create([],["notification" => function($notification, $severity, $message, $code, $bytes_cur, $bytes_max) use($progress) { + /* avoid bytes_max bug of older PHP versions */ + $maxbytes = 0; + return stream_context_create([],["notification" => function($notification, $severity, $message, $code, $bytes_cur, $bytes_max) use($progress, &$maxbytes) { + if ($bytes_max > $maxbytes) { + $maxbytes = $bytes_max; + } switch ($notification) { case STREAM_NOTIFY_CONNECT: $progress(0); break; case STREAM_NOTIFY_PROGRESS: - $progress($bytes_max ? $bytes_cur/$bytes_max : .5); + $progress($maxbytes > 0 ? $bytes_cur/$maxbytes : .5); break; case STREAM_NOTIFY_COMPLETED: - /* this is not generated, why? */ + /* this is sometimes not generated, why? */ $progress(1); break; }