[PHP-WEBMASTER] [web-downloads] main: Switch to uniqid to make sure hashes as unique

Author: Shivam Mathur (shivammathur)
Date: 2026-04-02T06:28:21+05:30

Commit: Switch to uniqid to make sure hashes as unique · php/web-downloads@cd24f85 · GitHub
Raw diff: https://github.com/php/web-downloads/commit/cd24f8578a5003fbb5d453b33887ba4d6ce3ada4.diff

Switch to uniqid to make sure hashes as unique

Changed paths:
  M src/Console/Command/PhpCommand.php
  M src/Http/Controllers/PeclController.php
  M src/Http/Controllers/PhpController.php
  M src/Http/Controllers/SeriesDeleteController.php
  M src/Http/Controllers/SeriesInitController.php
  M src/Http/Controllers/SeriesStabilityController.php
  M src/Http/Controllers/SeriesUpdateController.php

Diff:

diff --git a/src/Console/Command/PhpCommand.php b/src/Console/Command/PhpCommand.php
index ae1319f..ea82c62 100644
--- a/src/Console/Command/PhpCommand.php
+++ b/src/Console/Command/PhpCommand.php
@@ -56,7 +56,7 @@ public function handle(): int
             }

             foreach ($filteredFiles as $filepath) {
- $hash = hash('sha256', $filepath) . time();
+ $hash = hash('sha256', $filepath) . uniqid('', true);
                 $tempDirectory = "/tmp/php-" . $hash;

                 if (is_dir($tempDirectory)) {
diff --git a/src/Http/Controllers/PeclController.php b/src/Http/Controllers/PeclController.php
index a0194cd..764f3be 100644
--- a/src/Http/Controllers/PeclController.php
+++ b/src/Http/Controllers/PeclController.php
@@ -52,7 +52,7 @@ public function execute(array $data): void
     protected function fetchExtension(string $extension, string $ref, string $url, #[\SensitiveParameter] string $token): void
     {
         $directory = getenv('BUILDS_DIRECTORY') . "/pecl";
- $filepath = $directory . "/$extension-$ref-" . hash('sha256', $url) . time() . ".zip";
+ $filepath = $directory . "/$extension-$ref-" . hash('sha256', $url) . uniqid('', true) . ".zip";

         if(!is_dir($directory)) {
             umask(0);
diff --git a/src/Http/Controllers/PhpController.php b/src/Http/Controllers/PhpController.php
index 56da407..c6491a3 100644
--- a/src/Http/Controllers/PhpController.php
+++ b/src/Http/Controllers/PhpController.php
@@ -44,7 +44,7 @@ protected function execute(array $data): void
      */
     private function fetchPhpBuild(string $url, #[\SensitiveParameter] string $token): void
     {
- $hash = hash('sha256', $url) . time();
+ $hash = hash('sha256', $url) . uniqid('', true);

         $directory = getenv('BUILDS_DIRECTORY') . "/php";

diff --git a/src/Http/Controllers/SeriesDeleteController.php b/src/Http/Controllers/SeriesDeleteController.php
index 0dbad82..1e4535e 100644
--- a/src/Http/Controllers/SeriesDeleteController.php
+++ b/src/Http/Controllers/SeriesDeleteController.php
@@ -30,7 +30,7 @@ protected function validate(array $data): bool
     protected function execute(array $data): void
     {
         $directory = getenv('BUILDS_DIRECTORY') . '/series';
- $hash = hash('sha256', $data['php_version']) . time();
+ $hash = hash('sha256', $data['php_version']) . uniqid('', true);
         $file = $directory . '/series-delete-' . $hash . '.json';
         file_put_contents($file, json_encode($data));
     }
diff --git a/src/Http/Controllers/SeriesInitController.php b/src/Http/Controllers/SeriesInitController.php
index 2e78f57..4181e02 100644
--- a/src/Http/Controllers/SeriesInitController.php
+++ b/src/Http/Controllers/SeriesInitController.php
@@ -31,7 +31,7 @@ protected function validate(array $data): bool
     protected function execute(array $data): void
     {
         $directory = getenv('BUILDS_DIRECTORY') . '/series';
- $hash = hash('sha256', $data['php_version']) . time();
+ $hash = hash('sha256', $data['php_version']) . uniqid('', true);
         $file = $directory . '/series-init-' . $hash . '.json';
         file_put_contents($file, json_encode($data));
     }
diff --git a/src/Http/Controllers/SeriesStabilityController.php b/src/Http/Controllers/SeriesStabilityController.php
index 9acff0d..75b6e04 100644
--- a/src/Http/Controllers/SeriesStabilityController.php
+++ b/src/Http/Controllers/SeriesStabilityController.php
@@ -30,7 +30,7 @@ protected function validate(array $data): bool
     protected function execute(array $data): void
     {
         $directory = getenv('BUILDS_DIRECTORY') . '/series';
- $hash = hash('sha256', $data['php_version']) . time();
+ $hash = hash('sha256', $data['php_version']) . uniqid('', true);
         $file = $directory . '/series-stability-' . $hash . '.json';
         file_put_contents($file, json_encode($data));
     }
diff --git a/src/Http/Controllers/SeriesUpdateController.php b/src/Http/Controllers/SeriesUpdateController.php
index 9492ac8..891eb9f 100644
--- a/src/Http/Controllers/SeriesUpdateController.php
+++ b/src/Http/Controllers/SeriesUpdateController.php
@@ -51,7 +51,7 @@ protected function execute(array $data): void
             'ref' => $data['ref'],
         ];

- $hash = hash('sha256', $data['php_version'] . $data['vs_version'] . $data['library']) . microtime(true);
+ $hash = hash('sha256', $data['php_version'] . $data['vs_version'] . $data['library']) . uniqid('', true);
         $file = $seriesDirectory . '/series-update-' . $hash . '.json';

         file_put_contents($file, json_encode($payload));