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 /** * Delete a file,...

php fsockopen伪造post与get方法的详解

fsockopen 伪造 post和get方法哦,如果你正在找 伪造 post和get方法的php处理代码这款不错哦。复制代码 代码如下:<?php//fsocket模拟post提...

PHP中Header使用的HTTP协议及常用方法小结

本文实例总结了PHP中Header使用的HTTP协议及常用方法。分享给大家供大家参考。具体方法如下: 复制代码 代码如下:<?PHP function https($nu...

php设计模式之单例模式代码

php设计模式之单例模式的例子,供大家参考,具体内容如下 <?php /** * php设计模式 单例模式 */ class Fruit{...

php防止sql注入的方法详解

一、什么是SQL注入式攻击?   所谓SQL注入式攻击,就是攻击者把SQL命令插入到Web表单的输入域或页面请求的查询字符串,欺骗服务器执行恶意的SQL命令。在某些表单...