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 时间日期操作实战

常见常用的时间函数: 1.time(); //取得1970/1/1 00:00:00 到现在的总秒数 <?echo time();?> 2.mktime(); //设定时间...

PHP面向对象学习笔记之一 基础概念

1> if( "false" ) 等效于 if( true), 因为非空字符串是true 2> 检查数据类型: is_array(); is_object(); is_str...

php上传大文件设置方法

打开php.ini,首先找到 ;;;;;;;;;;;;;;;; ; file uploads ; ;;;;;;;;;;;;;;;; 区域,有影响文件上传的以下几个参数: file...

基于PHP遍历数组的方法汇总分析

1. foreach()foreach()是一个用来遍历数组中数据的最简单有效的方法。#example1:复制代码 代码如下:<?php$colors= array('red','...

无需重新编译php加入ftp扩展的解决方法

首先,进入源码目录cd php-5.2.13/ext/ftp #运行phpize生成configure/usr/local/php/bin/phpize #编译,指定php-config...