aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« on: Sep 23, 2007, 10:54:36 AM »
i have a problem that i am sure a lot of you have run into before... does a remote file exist? a function that works just like PHP's built in "file_exists", but for remote files, or URL's, whatever you want to call it. searching the PHP manual, this is the function I have found and currently am using:
//check if an external file exists function url_exists($url) {
the problem is that it is very slow.. just doing a simple parse time test with the function disabled and enabled, here are the results. the number of elements that access the function for this example is about 15, so its looped that many times.
using the function: Parsed in 2.796 secs not using the function (to check if the elements exist before showing them): Parsed in 0.228 secs
so you can clearly see the 2.5 second difference there, which is pretty bad . if your curious as to WHY i need this function or why its looped so many times, its for user avatars that arent uploaded through the script, when they provide a URL to that avatar in their profile. so for example on a forum thread with 15 entries, all with an avatar, this function is looped that many times and would cause the page to load this slow.
my question is, is there are better way to check if a file exists on an external server? preferably much faster than what I am doing here, because this just won't work
Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« Reply #1 on: Sep 23, 2007, 11:37:36 AM »
I think the 2.5 seconds isn't too bad, considering you are connecting to a remote site 15 times. This comes down to connecting to a remote site to check if the file exists in 0.17 seconds. If the time it takes is really a problem, why bother checking at all? Just include the remote url in your img tag.
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 7975
40807 credits Members referred : 3
« Reply #3 on: Sep 23, 2007, 01:22:01 PM »
Just remove the gethostbyname() call from your function. cURL is great but it uses fsocket too, so I guess the fastest way is a modified version of what you do now
aka J Love Community Supporter?
Bill Gates is my home boy
Gender:
Posts: 884
1636 credits Members referred : 4
« Reply #4 on: Sep 24, 2007, 12:46:58 AM »
thanks for the help guys, i decided the best solution was to take nikolas' suggestion, and move the check to see if the avatar exists to actually when updating the profile (dont know why i didnt do this before..).. and simply removing the check from the function that checks if it exists, since its done when updating.