开发者

php file exists problem - 1000's of files

I have a folder that contains 1000+ sub folders. In each subfolder there are 1-800 images, plus a thumbs folder with the same number of smaller versions. In total there are around 18000 photos and 18000 thumbs

I ha开发者_开发技巧ve created a script to run occasionally to check if everything is present (all paths, folders and photo names are stored in database).

Using either file_exist() or is_file(), plus clearstatcache(), I run a loop to my db records to check if everything is ok.

To check if the script actually works, I have included a check field in my table structure:

photo_present, SET(Y,N)

Each time I run the script each photo validated will have the photo_present flag set to Y.

After only a few records, 300-800, the script gives an internal server error 500.

I checked my table and I know that the script has run for a while since I see the photo_present field is set to Y.

My question is how to optimize it so either file_exist() or is_file() will continue to work until all the files have been checked?


How are you running the script? If it's by hitting the web page, it could be that your server caps the runtime of a script at 30 seconds or so and is killing PHP after that time, resulting in an Internal Server Error. The same could be true if it's being run via cron, but that's less likely.


Are you sure this isn't a script timeout? Check http://php.net/manual/en/function.set-time-limit.php

I myself consider glob being a good alternative when browsing folders and files, you might be able to figure out something.

<?php
//get all image files 
$files = glob("{*.jpg,*.JPG,*.gif,*.GIF,*.png,*.PNG,*.cr2,*.CR2,*.DNG,*.dng}", GLOB_BRACE);

//print each file name
foreach($files as $file)
{
    //Do your db validation here.
    //echo "<a href=\"$file\" style=\"display:block;\">$file</a>";
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜