生成大型虚拟文件的算法 [英] Algorithm to Generate a LARGE Dummy File
本文介绍了生成大型虚拟文件的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人用PHP生成了快速算法来生成大型伪文件(例如500MB-2GB)吗?
Has anyone written a Fast Algorithm that generates a LARGE dummy file in PHP, say 500MB-2GB?
推荐答案
If you don't care about the file contents at all, you can just seek to any position and write something:
$f = fopen('largefile', 'wb');
fseek($f, 2 * 1000 * 1000 * 1000, SEEK_SET);
fwrite($f, 'after 2 GB');
fclose($f);
如果操作系统和文件系统支持稀疏文件,则该文件确实会很大,但不会实际上占用了超过几个字节的磁盘空间.
If the OS and filesystem support sparse files, the file will be really big, but not actually take more than a couple of bytes of disk space.
这篇关于生成大型虚拟文件的算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文