Home >Backend Development >PHP Tutorial >PHP中创建空文件的代码[file_put_contents vs touch]_PHP

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

WBOY
WBOYOriginal
2016-06-01 12:13:40981browse

I has passed a small test to check which function is faster to create a new file.

file_put_contents vs touch
复制代码 代码如下:
for($i = ; $i {
file_put_contents('dir/file'.$i, '');
}
?>

Average time: 0,1145s
复制代码 代码如下:
for($i = ; $i {
touch('dir/file'.$i);
}
?>

Average time: 0,2322s

所以,file_put_contents比touch快,大约两倍。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:fgetcvs在linux的问题_PHPNext article:PHP 版本讲解_PHP