BuildMyWeb Posted December 29, 2014 Share Posted December 29, 2014 i need to count the number of image files on a remote server not in my network. ive come across a suggestion to use @getimagesize($img_url) the above works but is really slow. anyone able to suggest a better method? Link to comment https://forums.phpfreaks.com/topic/293505-count-image-files-on-remote-server/ Share on other sites More sharing options...
CroNiX Posted December 29, 2014 Share Posted December 29, 2014 It's probably slow because it's on a remote server, which means it has to retrieve the file first before it can run a function on it. Link to comment https://forums.phpfreaks.com/topic/293505-count-image-files-on-remote-server/#findComment-1501087 Share on other sites More sharing options...
BuildMyWeb Posted December 29, 2014 Author Share Posted December 29, 2014 yes cronix. ive read that it will always be exceedingly slow to use in this manner. and makes sense. hence why im looking for an alternative Link to comment https://forums.phpfreaks.com/topic/293505-count-image-files-on-remote-server/#findComment-1501089 Share on other sites More sharing options...
Jacques1 Posted December 29, 2014 Share Posted December 29, 2014 Use an appropriate library, not this crappy built-in HTTP stuff. PHP supports cURL which is a well known library for HTTP and other protocols. Make parallel HEAD requests (CURLOPT_NOBODY set to true). This way you just ask the webserver for the response code rather than unnecessarily downloading the actual file content. And the requests don't have to wait for each other. Depending on how exactly the counting works, you may also optimize that. Link to comment https://forums.phpfreaks.com/topic/293505-count-image-files-on-remote-server/#findComment-1501090 Share on other sites More sharing options...
CroNiX Posted December 29, 2014 Share Posted December 29, 2014 It seems if you want to "count" it, you could just use CURL like this to only examine the file header and if the status returned is 200 than increment a counter or something. Link to comment https://forums.phpfreaks.com/topic/293505-count-image-files-on-remote-server/#findComment-1501091 Share on other sites More sharing options...
BuildMyWeb Posted December 30, 2014 Author Share Posted December 30, 2014 thanks guys. thats a better solution. Link to comment https://forums.phpfreaks.com/topic/293505-count-image-files-on-remote-server/#findComment-1501094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.