The glob() function in PHP?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
4 views
Just recently, the project needed a search function for files by mask glob(). But that is in thought whether to use it, and how much it loads the server.


The task is as follows:

There is an object, let's say a car, he's got 20-30 photos that are stored in 5 folders with different sizes. Sootvetsvenno in the presence of base 20-30000 object pictures can be approximately 150-200, 000 files. A wildcard search will be performed something like this: "/path/photos/[obj_id]_*.jpg" now, something really confuses me to use this feature... And I can't dig up information on loads.
by | 4 views

5 Answers

0 like 0 dislike
Create 200k files:
#!/bin/bash dir="/test" ctr=1 range=30000 while [ ${ctr} -lt 200001 ]; do id=${RANDOM} let "id %= ${range}" `touch "${dir}/${id}_${ctr}.jpg"` let ctr=ctr+1 done

Check:
~> ./test_glob ~> ls -1 /test | wc-l 200000 

Test performance:
<?php\r\r$dir = '/test/';\r$id = rand( 1, 30000 );\r$pattern = $dir . $id . '_*.jpg';\r\r$time_start = microtime(true);\r\r$photos = glob( $pattern );\r\r$time_end = microtime(true);\r$time = $time_end - $time_start;\r\recho 'execution time is ', $time, ' seconds', PHP_EOL;\r\rprint_r($photos);\r</code>

\r
~> php ./test_glob.php execution time is 0.15708804130554 seconds Array ( [0] => /test/23513_10050.jpg [1] => /test/23513_10631.jpg [2] => /test/23513_121888.jpg [3] => /test/23513_150044.jpg [4] => /test/23513_167985.jpg [5] => /test/23513_185798.jpg [6] => /test/23513_188480.jpg [7] => /test/23513_193143.jpg [8] => /test/23513_68603.jpg ) 

\r
Draw conclusions.
by
0 like 0 dislike
IMHO, to store 200,000 files in a folder is not the best idea. I would make a folder structure like 12/34/56/78/90/*.jpg, where 1234567890 — obj_id. Although, of course, depends strongly on FS and free memory on the server
by
0 like 0 dislike
To execute it will be expensive, but you can test it yourself (small test-script). Better index your existing files into the database, and the new bring back, immediately after adding...
by
0 like 0 dislike
Don't know whether fixed already, but habrahabr.ru/blogs/infosecurity/105894/
by
0 like 0 dislike
Sobstno it is and reminded.:))
by

Related questions

0 like 0 dislike
4 answers
asked Apr 1, 2019 by eidicon
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
28,070 users