当fwrite完成时,php继续运行

时间:2013-02-17 15:27:14

标签: php fwrite

我需要加入两个csv文件然后读取整个合并文件 问题是当fwrite做它的工作时,php继续执行功能 所以当fwrite开始时需要暂停/暂停。

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);
}

当我运行Doo::dictionary()时,language_pack.csv文件只包含第一个csv文件内容。

0 个答案:

没有答案