PHP中创建空文件的代码[file_put_contents vs touch]_php教程-查字典教程网
PHP中创建空文件的代码[file_put_contents vs touch]
PHP中创建空文件的代码[file_put_contents vs touch]
发布时间:2016-12-29 来源:查字典编辑
摘要:Ihaspassedasmalltesttocheckwhichfunctionisfastertocreateanewfile.file_...

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快,大约两倍。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新php教程学习
    热门php教程学习
    编程开发子分类