Directory Size to MySQL Table

时间:2015-05-12 23:28:27

标签: php

I use this function to get directory size and store total on MySQL with Cronjob

(function(doc) {})(document);

On large directory > 30 GB and hundreds of files, is very slow an load 100% CPU

Exist an equivalent function to get directory size without load CPU 100% and most quickly?

TKS HID

1 个答案:

答案 0 :(得分:1)

以这种方式获得尺寸:

chdir ($DirectoryPath);
$bytes = intval(preg_replace('/[\D]+/','',system('du',$result)));

这将获取目录和子目录大小的详细信息。

system('du',$result)

这将删除除数字

以外的所有字符
preg_replace('/[\D]+/','',

这会将返回的数字字符串转换为整数值。

intval()