Dlaczego to musi być skrypt? PHP nie nadaje się do takich rzeczy jak sortowanie plików o takich wielkościach (chyba że zrzucimy to na bazę danych, ale tutaj PHP miałoby tylko rolę "odczytaj linię i wrzuć do bazy"). Zasadnicze pytanie jest takie: czy chcesz ten plik posortować, czy chcesz mieć skrypt w PHP, który Ci to posortuje?
Edit: Postanowiłem jednak się zabawić i napisać skrypt w PHP (bez udziału baz danych) oparty na plikach tymczasowych (w celu ograniczenia zużycia pamięci). Nie sortuje on jednak alfabetycznie, ale tylko po długości.
<?php
$fnameIn = 'input.txt';
$fnameOut = 'output.txt';
$tmpFilePrefix = '/tmp/xx_length.';
$chunks = 4; // how many files per one length
//@todo check if fnameIn exists
/* step 1, separate lines with same lengths into different files, they're also chunked */
$f = fopen($fnameIn, 'r'); $maxLength = -1;
$lineLength = mb_strlen($line);
if ($lineLength > $maxLength) {
$maxLength = $lineLength;
}
if (!isset($chunkArr[$lineLength])) { $chunkArr[$lineLength] = 0;
//@todo clear $tmpFname file (with all chunks). When "step 2" won't remove tmp files somehow, we will have doubled content, couse of FILE_APPEND flag
}
$tmpFname = $tmpFilePrefix.$lineLength.'_'.($chunkArr[$lineLength]++%$chunks);
file_put_contents($tmpFname, $line, FILE_APPEND); }
/* step 2, merge and delete all temporary files
This may also be memory consumpting (ex. when all lines have same length and we have chunks set to 1), but in most cases should be better than sorting whole file at once
*/
$f = fopen($fnameOut, 'w');
for($i=0; $i<=$maxLength; $i++) {
// check all chunks
for($k=0;$k<$chunks;$k++) {
$tmpFname = $tmpFilePrefix.$i.'_'.$k;
}
}
}
Co do samego jednorazowego posortowania to nie wiem jak pod Windowsem, ale polecenie, które zadziała pod Linuksem wkleiłem Ci w poprzednim wątku
http://forum.php.pl/index.php?s=&showt...st&p=979723. Na windowsie możesz zainstalować sobie cygwin - konsola i narzędzia konsolowe z linuksa.