fix hogging by opening each phar; need to do more about that
authorMichael Wallner <root@s201809.m6w6.name>
Wed, 3 Apr 2019 11:51:55 +0000 (13:51 +0200)
committerMichael Wallner <root@s201809.m6w6.name>
Wed, 3 Apr 2019 11:52:25 +0000 (13:52 +0200)
public/index.php

index 72a97f62542632c2f024f43c8c2999339859cbfb..b403d19733946259f0a6f42c56908830c48d749c 100644 (file)
@@ -35,25 +35,34 @@ function sigof($phar, $typ) {
 
 function package_versions($package) {
        $versions = [];
-       foreach (glob("phars/$package/*.ext.phar*") as $phar) {
-               list($name, $enc) = explode(".ext.phar", basename($phar));
+       foreach (glob("phars/$package/*.ext.phar") as $phar) {
+               $name = basename($phar, ".ext.phar");
                $data = new Phar($phar);
                $meta = $data->getMetadata();
+               unset($data);
+
                if ($meta) {
                        $release = $meta["release"];
                } else {
                        $release = substr($name, strlen($package)+1);
                }
 
-               foreach (SIGS as $sigtyp => $sigext) {
-                       if (file_exists($sigdat = sigof($phar, $sigext))) {
-                               $sigs[$sigtyp] = $sigdat;
+               foreach (["", ".gz", ".bz2"] as $enc) {
+                       $file = $phar . $enc;
+                       if (!is_file($file)) {
+                               continue;
+                       }
+
+                       foreach (SIGS as $sigtyp => $sigext) {
+                               if (file_exists($sigdat = sigof($file, $sigext))) {
+                                       $sigs[$sigtyp] = $sigdat;
+                               }
                        }
+                       $size = filesize($file);
+                       $date = isset($meta["date"]) ? strtotime($meta["date"]) : filemtime($file);
+                       $pharext = isset($meta["version"]) ? $meta["version"] : "2.0.1";
+                       $versions[$release][$enc] = ["phar" => $file] + compact("date", "size", "pharext", "sigs");
                }
-               $size = filesize($phar);
-               $date = isset($meta["date"]) ? strtotime($meta["date"]) : filemtime($phar);
-               $pharext = isset($meta["version"]) ? $meta["version"] : "2.0.1";
-               $versions[$release][$enc] = compact("phar", "date", "size", "pharext", "sigs");
                uksort($versions[$release], function($a, $b) {
                        $al = strlen($a);
                        $bl = strlen($b);