信息发布→ 登录 注册 退出

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

发布时间:2026-01-11

点击量:
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_contents比touch快,大约两倍。
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!