PHP中创建空文件的代码[file_put_contents vs touch]
更新时间:2012年01月20日 13:11:54 作者:
php中用file_put_contents比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快,大约两倍。
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快,大约两倍。
相关文章
解决出现SoapFault (looks like we got no XML document)的问题
下面小编就为大家带来一篇解决出现SoapFault (looks like we got no XML document)的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-06-06
php解析html类库simple_html_dom(详细介绍)
一直以来使用php解析html文档树都是一个难题。Simple HTML DOM parser 帮我们很好地解决了这个问题。可以通过这个php类来解析html文档,对其中的html元素进行操作 (PHP5+以上版本)2013-07-07
PHP使用preg_split()分割特殊字符(元字符等)的方法分析
这篇文章主要介绍了PHP使用preg_split()分割特殊字符(元字符等)的方法,结合具体实例形式分析了php正则分割的操作技巧与注意事项,需要的朋友可以参考下2017-02-02
简单谈谈PHP中的include、include_once、require以及require_once语句
include() 、require()语句包含并运行指定文件。这两结构在包含文件上完全一样,唯一的区别是对于错误的处理。require()语句在遇到包含文件不存在,或是出错的时候,就停止即行,并报错。include()则继续即行。2016-04-04
PHP使用preg_split和explode分割textarea存放内容的方法分析
这篇文章主要介绍了PHP使用preg_split和explode分割textarea存放内容的方法,结合实例形式分析preg_split和explode函数的功能、使用技巧与文本字符串分割过程中的相关注意事项,需要的朋友可以参考下2017-07-07


最新评论