加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 06:03:37 所属栏目:PHP教程 来源:网络整理
导读:I has passed a small test to check which function is faster to create a new file. file_put_contents vs touch div class="codetitle" a style="CURSOR: pointer" data="20971" class="copybut" id="copybut20971" onclick="doCopy('code20971')" 代码

I has passed a small test to check which function is faster to create a new file. file_put_contents vs touch
<div class="codetitle"><a style="CURSOR: pointer" data="20971" class="copybut" id="copybut20971" onclick="doCopy('code20971')"> 代码如下:<div class="codebody" id="code20971">
<?php
for($i = ; $i < 100; $i++)
{
file_put_contents('dir/file'.$i,'');
}
?>

Average time: 0,1145s
<div class="codetitle"><a style="CURSOR: pointer" data="12685" class="copybut" id="copybut12685" onclick="doCopy('code12685')"> 代码如下:<div class="codebody" id="code12685">
<?php
for($i = ; $i < 100; $i++)
{
touch('dir/file'.$i);
}
?>

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读