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

yipeiwu_com6年前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地址引用(php地址引用的效率问题)

复制代码 代码如下: <?php echo 'begin time:'.$begin=microtime(false).'<br/>';//begin to count...

php日历[测试通过]

比较不错的一款php日历代码复制代码 代码如下:<?php /** * 日历 * * Copyright(c) 2007 by 陈毅鑫(深空). All rights reserv...

PHP实现求解最长公共子串问题的方法

本文实例讲述了PHP实现求解最长公共子串问题的方法。分享给大家供大家参考,具体如下: 题目:如果字符串一的所有字符按其在字符串中的顺序出现在另外一个字符串二中,则字符串一称之为字符串二的...

php抓取页面与代码解析 推荐

得到数据我们不能直接输出,往往需要对内容进行提取,然后再进行格式化,以更加友好的方式显现出来。下面先简单说一下本文的主要内容: 一、 PHP抓取页面的主要方法: 1. file()函数...

php使用curl打开https网站的方法

本文实例讲述了php使用curl打开https网站的方法。分享给大家供大家参考。具体实现方法如下: $url = 'https://www.google.com.hk'; $ch...