为特大文件获取MD5校验和 [英] Get MD5 Checksum for Very Large Files

查看:116
本文介绍了为特大文件获取MD5校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个脚本来读取目录中的所有文件,并为每个文件返回md5散列。但是,它不会为一个相当大的文件渲染。我假设解释器为最大处理时间设置了一些值,并且因为获取该值需要很长时间,所以它只是跳到其他文件。无论如何,通过PHP获取大文件的md5校验和?如果没有,是否可以通过cpanel做一个chron工作?我在那里给了它一个镜头,但似乎并没有处理我的md5sum命令:我从来没有收到一封带有散列的电子邮件。这是我已经写过的PHP。这是一个非常简单的代码和作品文件的合理大小的文件:

 函数md5_dir($ dir){
if(is_dir($ dir)){
if($ dh = opendir($ dir)){
while(($ file = readdir($ dh))!== false){
echo nl2br($ file。\\\
。md5_file($ file)。\\\
\\\
);
}
closedir($ dh);




解决方案

虽然我无法用PHP 5.2或5.3和2GB文件重现它,但问题似乎出现在32位PHP版本上。

即使如此,它也不是一个非常好的解决方案,你可以尝试让系统进行维护。

  echo system(md5sum test.txt); 




46d6a7bcbcf7ae0501da341cb3bae27c test.txt blockquote>

I've written a script that reads through all files in a directory and returns md5 hash for each file. However, it renders nothing for a rather large file. I assume that the interpreter has some value set for maximum processing time, and since it takes too long to get this value, it just skips along to other files. Is there anyway to get an md5 checksum for large files through PHP? If not, could it be done through a chron job with cpanel? I gave it a shot there but it doesn't seem that my md5sum command has ever been processed: I never get an email with the hash. Here's the PHP I've already written. It's a very simple code and works file for files of a reasonable size:

function md5_dir($dir) {
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                echo nl2br($file . "\n" . md5_file($file) . "\n\n");
            }
            closedir($dh);
        }
    }
}

解决方案

While i couldn't reproduce it with PHP 5.2 or 5.3 with a 2GB file the issue seems to come up on 32bit PHP builds.

Even so it's not a really nice solution you could try to let the system to the hasing

echo system("md5sum test.txt");

46d6a7bcbcf7ae0501da341cb3bae27c test.txt

这篇关于为特大文件获取MD5校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆