Created
May 29, 2013 19:41
-
-
Save donatj/5673199 to your computer and use it in GitHub Desktop.
Add percent markers to a SQL file for importing. Currently limited to 2 gigs in size.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
$file = @$argv[1]; | |
if( !is_file($file) ) { | |
die('Please provide a SQL file' . PHP_EOL); | |
} | |
$file_size = filesize($file); | |
$last_percent = false; | |
if (($handle = fopen($file, "r")) !== FALSE) { | |
while (($data = fgets($handle, 1000)) !== FALSE) { | |
echo $data; | |
$percent = intval( (ftell($handle) / $file_size) * 100 ); | |
if($percent != $last_percent && $percent % 2 == 0) { | |
echo PHP_EOL . "SELECT '$percent%';" . PHP_EOL . PHP_EOL; | |
$last_percent = $percent; | |
} | |
} | |
fclose($handle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment