html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

PHP中创建空文件的代码[file_put_contents vs touch]-PHPphp技巧 file_put_contents,touch

[ ] 已经帮助:人解决问题
I has passed a small test to check which function is faster to create a new file.

file_put_contents vs touch
复制代码 代码如下:

<?php
for($i = ; $i < 100; $i++)
{
file_put_contents('dir/file'.$i, '');
}
?>

Average time: 0,1145s
复制代码 代码如下:

<?php
for($i = ; $i < 100; $i++)
{
touch('dir/file'.$i);
}
?>

Average time: 0,2322s

所以,file_put_contentstouch快,大约两倍。
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助