What is the best way to write a large file to disk in PHP?

后端 未结 3 1526
温柔的废话
温柔的废话 2020-12-14 10:49

I have a PHP script that occasionally needs to write large files to disk. Using file_put_contents(), if the file is large enough (in this case around 2 MB), the

3条回答
  •  囚心锁ツ
    2020-12-14 11:05

    Try this answer:

        $file   = fopen("file.json", "w");
    
        $pieces = str_split($content, 1024 * 4);
        foreach ($pieces as $piece) {
            fwrite($file, $piece, strlen($piece));
        }
    
        fclose($file);
    

提交回复
热议问题