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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-17 09:13:131025browse

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_contentstouch快,大约两倍。
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