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)
- Notification emails should use display name in all circumstances
- [2.1.x] open_basedir restriction warnings in php 8+ HOT 14
- "host" command (on specific IPs) blocking the PHP workers indefinitively HOT 9
- Undefined value from adding member to group HOT 2
- [2.1.x] Could not retrieve the file current-version.js HOT 12
- [2.1.x] Open_basedir warnings with file permission profile
- Quick reply seems to ignore [nobbc] for unmatched opening [li] tags HOT 1
- integrate_error_types function call not working HOT 1
- Upgrader - undefined function "allowedTo()" errors
- Error for events with no topic on board index
- Incorrect error "you are banned" in stale session HOT 21
- Export PMs/Profile data error. HOT 6
- Language switcher loses post preview and attachments; error with new attachment UI HOT 1
- Attachments UI popup width hardcoded? HOT 12
- SearchAPI-Custom.php - Undefined variable: excludedWord
- Mark read doesn't work for recycled posts HOT 1
- [quote date] and [time] need sanity checks
- 2.1.4 template editor, breaks files HOT 7
- Emojis cannot be used in SMF logo fields
- Unapproving topic in Recycle bin causes error or negative numbers HOT 1
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.