This time for everyone to bring PHP to achieve large file cutting and merging steps, PHP implementation of large file cutting and merger considerations, the following is the actual case, together to see.
Split code
split.php
<?php$i = 0; Split block number $fp = fopen ("Hadoop.sql", "RB"); The file to be split $file = fopen ("Split_hash.txt", "a"); The text file that records the split information, the actual production environment exists redis more suitable while (!feof ($fp)) { $handle = fopen ("hadoop.{ $i}.sql "," WB "); Fwrite ($handle, Fread ($fp, 5242880));//Cut the block size 5m fwrite ($file, "hadoop.{ $i}.sql\r\n "); Fclose ($handle); Unset ($handle); $i + +;} Fclose ($FP); fclose ($file); echo "OK";
Merge code
merge.php
<?php$hash = file_get_contents ("Split_hash.txt"); Read the information of the segmented file $list = explode ("\ r \ n", $hash); $fp = fopen ("Hadoop2.sql", "AB"); The merged file name, foreach ($list as $value) { if (!empty ($value)) { $handle = fopen ($value, "RB"); Fwrite ($fp, Fread ($handle, FileSize ($value))); Fclose ($handle); Unset ($handle); }} Fclose ($FP); echo "OK";
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
thinkphp Framework Let page redirection method summary
PHP uses regular expressions to match city-province