当前位置:Gxlcms > PHP教程 > PHP中创建空文件的代码[file_put_contentsvstouch]

PHP中创建空文件的代码[file_put_contentsvstouch]

时间:2021-07-01 10:21:17 帮助过:6人阅读

I has passed a small test to check which function is faster to create a new file.
file_put_contents vs touch

代码如下:


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


Average time: 0,1145s

代码如下:


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


Average time: 0,2322s
所以,file_put_contents比touch快,大约两倍。

以上就介绍了 PHP中创建空文件的代码[file_put_contents vs touch],包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行