Code Monkey home page Code Monkey logo

Comments (11)

jdarwood007 avatar jdarwood007 commented on May 24, 2024

We should try to see if we can do a "ls dir | wc -l" first and if not then fall back. Perhaps move this to a scheduled task once a day and then rely on updating the cache values to keep a semi-accurate count.

from smf.

joshuaadickerson avatar joshuaadickerson commented on May 24, 2024

Where is that code at?

from smf.

joshuaadickerson avatar joshuaadickerson commented on May 24, 2024

Oh yeah, besides that, we are using PHP 5 now... let's use scandir() instead. I found that using ls is also faster when I had similar issues at work.

from smf.

 avatar commented on May 24, 2024

@joshuaadickerson It's at the bottom of ManageAttachments.php

I should think that something like this would be far more efficient than looping through all the files.

// Get approximate file size of the entire directory.
echo round(filesize($boarddir. '/attachments' ) / 1024);

// Count all the files except three (.htaccess, back/current dot-files)
echo count(scandir($boarddir. '/attachments')) - 3;

from smf.

emanuele45 avatar emanuele45 commented on May 24, 2024

Good point Josh, that could be a solution.

from smf.

joshuaadickerson avatar joshuaadickerson commented on May 24, 2024

I like @The-Craw's method. Get the file size of the files you want to exclude and subtract them if you want to be more precise but I don't think that is necessary.

from smf.

butch2k avatar butch2k commented on May 24, 2024

use

echo count(glob($boarddir. '/attachments/*',GLOB_NOSORT));

rather than scandir it's a bit much faster.
18007 files
500 scandir: 10.132883071899
18007 files
500 glob: 8.8571441173553

from smf.

emanuele45 avatar emanuele45 commented on May 24, 2024

50k files (20 times):

current: 3.9553589820862
glob: 3.5812120437622
scandir: 3.2565090656281

...I feel it really depends on many factors...

On the other hand, if I simply remove the if (in_array(blabla))

current: 1.9055411815643
glob: 3.5589849948883
scandir: 3.1512770652771

from smf.

butch2k avatar butch2k commented on May 24, 2024

low end server using PHP 5.4.9
1788 files
500 scandir: 3.1955649852753
1788 files
500 scandir (NO SORT): 2.4955389499664
1788 files
500 glob: 3.3973519802094
1788 files
500 dir read (NO in_array): 2.971538066864

on PHP5.4 scandir with SCANDIR_SORT_NONE seems the fatest of the lot.

need to check memory consumption as well especially for large directories.

from smf.

emanuele45 avatar emanuele45 commented on May 24, 2024

Memory used (peak from memory_get_peak_usage) by scandir for 55k files is about 9 MB. Nothing important.

But the real issue is that from that figures there is no real difference from one or another.
A 5% doesn't change anything if the issue is a timeout.

from smf.

emanuele45 avatar emanuele45 commented on May 24, 2024

It seems there is not much difference and probably the issue was server side.

Closing this one.

from smf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.