From a06f05f40a119a093cbec83520e99c329447d067 Mon Sep 17 00:00:00 2001 From: jakani24 Date: Sun, 10 Mar 2024 11:18:42 +0100 Subject: [PATCH] Update compile_database.php --- .../api/php/database/compile_database.php | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/server/cyberhex-code/api/php/database/compile_database.php b/src/server/cyberhex-code/api/php/database/compile_database.php index b27e533..f6016a5 100644 --- a/src/server/cyberhex-code/api/php/database/compile_database.php +++ b/src/server/cyberhex-code/api/php/database/compile_database.php @@ -7,6 +7,9 @@ function sort_hashes($inputFile, $excluded) { die("Unable to open input file."); } + // Initialize an array to hold batched hashes + $batchedHashes = array(); + // Read each line from the input file while (($line = fgets($handle)) !== false) { // Remove leading/trailing whitespace and split the line into words @@ -16,30 +19,27 @@ function sort_hashes($inputFile, $excluded) { if (in_array($hash, $excluded)) { continue; // Skip this hash } - + // Get the first two characters of the word $prefix = substr($hash, 0, 2); // Create the filename for the corresponding file $filename = "/var/www/html/database_srv/".$prefix . ".jdbf"; - // Open or create the file for writing - $fileHandle = fopen($filename, "a"); - if ($fileHandle === false) { - die("Unable to open/create file: $filename"); - } - - // Write the word to the file - fwrite($fileHandle, $line . PHP_EOL); - - // Close the file handle - fclose($fileHandle); + // Add the hash to the batched array + $batchedHashes[$filename][] = $line . PHP_EOL; } // Close the input file handle fclose($handle); + + // Write batched hashes to files + foreach ($batchedHashes as $filename => $hashes) { + // Open or create the file for writing + $fileContents = implode('', $hashes); + file_put_contents($filename, $fileContents, FILE_APPEND); + } } - function download_files($excluded){ //download from virusshare $file_count=485;