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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted December 29, 2014 Share Posted December 29, 2014 (edited) 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. Edited December 29, 2014 by Jacques1 1 Quote Link to comment Share on other sites More sharing options...
Solution CroNiX Posted December 29, 2014 Solution 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. 1 Quote Link to comment Share on other sites More sharing options...
BuildMyWeb Posted December 30, 2014 Author Share Posted December 30, 2014 thanks guys. thats a better solution. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.