Comments (11)
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.
Where is that code at?
from smf.
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.
@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.
Good point Josh, that could be a solution.
from smf.
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.
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.
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.
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.
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.
It seems there is not much difference and probably the issue was server side.
Closing this one.
from smf.
Related Issues (20)
- `$significant_decimals` generates noise
- [3.0]: Search results are not showing
- `composer lint-fix` doesn't work on windows commandline HOT 3
- `TypeError` in Repair Boards HOT 1
- First line of query gets cut off in query log HOT 1
- $txt['debug_query_which_took_at'] HOT 1
- [2.1] [3.0]: poster_name is member_name (private) not real_name (display)
- [3.0]: Links not rendered in search results
- [3.0]: Custom search index weirdness
- [2.1]: Notication emails for reply not sent if user also subscribe for the board HOT 2
- [3.0]: MariaDB doesn't have "REGEXP_LIKE" HOT 1
- [3.0]: Upgrade doesn't work HOT 2
- [3.0/2.1]: Installing packages/themes does not parse line breaks for the XML tags.
- [3.0]: Upgrade breaks after backup due to User::$me not being initialized
- [3.0]: New columns not being added to tables HOT 1
- [3.0]: Calling pg_version() with default connection is depracated as of PHP 8.1
- [3.0] Installer needs General language file? HOT 17
- [3.0]: Error while adding holidays
- [3.0]: Adding calendar event can cause max_execution_time to be exceeded HOT 3
- [3.0]: No option to delete events
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smf.