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

网络编程 发布日期:2024/10/25 浏览次数:1

正在浏览:PHP中创建空文件的代码[file_put_contents vs 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_contents比touch快,大约两倍。