Skip to content

Instantly share code, notes, and snippets.

@donatj
Created May 29, 2013 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donatj/5673199 to your computer and use it in GitHub Desktop.
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.
#!/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