首页 > 编程 > PHP > 正文

PHP中创建空文件的代码[file_put_contents vs touch]

2019-11-22 00:48:25
字体:
来源:转载
供稿:网友
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快,大约两倍。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表