I need to join two csv files and then read entire merged file.
the problem is php keeps executing function when fwrite
doing it's job.
so when fwrite
starts a pause/halt is needed.
static function dictionary($path) {
$language_pack = Doo::conf()->SITE_PATH . Doo::conf()->PROTECTED_FOLDER . 'languages/' . $lang . '/language_pack.csv';
Doo::joinFiles(array($lang_path, $common_lang_path), $language_pack);
// a pause must be done here until Doo::joinFiles finish it's job
return Doo::translator('Csv', $language_pack, array('delimiter' => '|','enclosure' => '"'));
}
// this function joins array of files and will merge them into single file
static function joinFiles(array $files, $result) {
if(!is_array($files)) {
throw new Exception('`$files` must be an array');
}
$wH = fopen($result, "w+");
foreach($files as $key => $file) {
$fh = fopen($file, "r");
while(!feof($fh)) {
fwrite($wH, fgets($fh));
}
fclose($fh);
unset($fh);
fwrite($wH, "\n"); //usually last line doesn't have a newline
}
fclose($wH);
unset($wH);
}
when i run Doo::dictionary()
then language_pack.csv file only contain the first csv file content.