0

So I have launched a classified ads website but I am realizing that the website is getting too slow when loading ... I have one single upload folder and one thumb_cache folder that contains 4680 images in each one of them ... so each folder has 4680 images .. I have a regular shared hosting ... Could this be why the site is slowing down ? Can over 4000 image files in one upload folder slow down a site ? I developed the site in PHP , would PHP have a hard time finding images in one folder with over 4000 image files ?

How should I organize the upload directory for better performance ? automatically create a folder within the upload folder for each ad with PHP ?

I get Warning:

imagepng() [function.imagepng]: Unable to open 
  '/home/content/72/9959172/html/thumb_cache/
   185x200__width__uploaded_files^classifi‌​ed_img^tractor61354.PNG' for writing: 
Stale NFS file handle in 
     /home/content/72/9959172/html/al/includes/funcs_lib.inc.php on line 1168
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • How are you currently retrieving the file path? – Fabor Aug 07 '14 at 14:29
  • Do you need all of the images at the same time? Your page will be slow because PHP, as any other programming language, needs time to get all of the images and load them to the local user (guessing you're not streaming them to the browser) – KhorneHoly Aug 07 '14 at 14:30
  • 1
    What aspect is "slow"? Is is downloading individual images? Is is something in PHP where you are iterating through files in the directory structure or reading the entire directory contents into memory? You haven't told us enough about the use case to get useful answers. – Mike Brant Aug 07 '14 at 14:31
  • so my site is a classifieds site and it loads slow , when I called my hosting service , it said that since all images of the website get stored into just one upload folder which contains now over 4800 image files , it could be the cause .. here is the warning I get Warning: imagepng() [function.imagepng]: Unable to open '/home/content/72/9959172/html/thumb_cache/185x200__width__uploaded_files^classified_img^tractor61354.PNG' for writing: Stale NFS file handle in /home/content/72/9959172/html/al/includes/funcs_lib.inc.php on line 1168 – Stevie Nix Aug 07 '14 at 14:47
  • Copied that warning to your Question where it is more relevant and more readable – RiggsFolly Aug 07 '14 at 14:53
  • possible duplicate of [Will too many files storing in one folder make HTTP request for one of them slow?](http://stackoverflow.com/questions/7016370/will-too-many-files-storing-in-one-folder-make-http-request-for-one-of-them-slow) – rlatief Aug 07 '14 at 15:15

2 Answers2

0

The answer is highly depends on Your server configuration. Basically -- yes, it POSSIBLE that this CAN be a problem when PHP is run under certain server installations.

In any way, it CAN AND WILL be a problem when You will start thinking about backups and maintenance.

Many servers and applications use two-letter prefixes on file's hashsums. For example, file with hash 75f5164e4bd2de372b99a3e2e2718aed will be placed under 75/f5/ folder. This can solve some problems.

Arenim
  • 4,097
  • 3
  • 21
  • 31
  • so my site is a classifieds site and it loads slow , when I called my hosting service , it said that since all images of the website get stored into just one upload folder which contains now over 4800 image files , it could be the cause .. here is the warning I get Warning: imagepng() [function.imagepng]: Unable to open '/home/content/72/9959172/html/thumb_cache/185x200__width__uploaded_files^classifi‌​ed_img^tractor61354.PNG' for writing: Stale NFS file handle in /home/content/72/9959172/html/al/includes/funcs_lib.inc.php on line 1168 – Stevie Nix Aug 07 '14 at 14:47
0

No this should not be issue, I had stored around 10000 images inside one folder... only if you are loading all the images of this folder on a single page will then have an issue.. but that too can be solved by a a jQuery lazy load plugin.

PHP has nothing to do about how files are stored on your OS, unless if you are retrieving it in a loop and processing those.

Ninad Ajnikar
  • 183
  • 1
  • 11