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

yipeiwu_com5年前PHP代码库
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_contentstouch快,大约两倍。

相关文章

PHP获取http请求的头信息实现步骤

PHP手册提供了现成的函数: getallheaders (PHP 4, PHP 5) getallheaders — Fetch all HTTP request headers 说明...

PHP实现的日历功能示例

PHP实现的日历功能示例

本文实例讲述了PHP实现的日历功能。分享给大家供大家参考,具体如下: <?php /* * Created by PhpStorm. * User: admin...

php不用GD库生成当前时间的PNG格式图象的程序第1/2页

<?php function set_4pixel($r, $g, $b, $x, $y) { global $sx, $sy, $pixels; $ofs = 3 * ($sx...

PHP实现在对象之外访问其私有属性private及保护属性protected的方法

本文实例讲述了PHP实现在对象之外访问其私有属性private及保护属性protected的方法。分享给大家供大家参考,具体如下: public 表示全局的访问权限,类内部外部子类都可以...

php !function_exists(&quot;T7FC56270E7A70FA81A5935B72EACBE29&quot;))代码解密

复制代码 代码如下: < ?php if (!function_exists("T7FC56270E7A70FA81A5935B72EACBE29")) { function T7...