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
file_put_contents()
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);