I have been having problems with users putting URL's to missing images in their account. Is there any PHP coding or function I can use that will not cause a major server strain or throw errors and will check if the file exists first. None of the images are hosted on my server.

Thanks for the help in advance!
Tim

    is_file depending on the URL wrappers
    or get_headers
    or fopen

      the is_file function only works on files that are on my server. the get_headers is for php 5. And fopen causes a server strain for some reason. Are there any other methods to test the URL's?

        fsockopen ?

        everything is going to cause some strain

          i tried using fsockopen, but even with an error catcher in place, it still threw errors. Maybe I had the coding wrong, but it was pulled straight from something i found in a search.

            With fsocketopen you connect to the server then request the file - but i don't see it being better than fopen. In all all likelihood it uses the same method as fopen.

            You could consider checking the files with a cron job at a time more convenient to your server, or get a faster one :-)

            -- seriously if fopen is slowing you down your site may well of out grown your host.

            how often are you needing to do this?

              at least ever 30 to 60 seconds. I am on a shared server and have no problem hosting my site on it. Just when I run the check file script, it causes the memory to go up and the server load goes way up. I can't afford another server 🙁

                $handle = @fopen("http://www.phpbuilder.com/images/lozzsssssgo.gif", "rb");
                
                if($handle === false){
                echo '<br>bad file';
                }else{
                echo '<br>good file';
                }
                

                i tested that on a few dozen sites, never took more than half a seconds and no effect on the account load.

                no way should that really be any problem even on a shared host, contact there support is the last thing i can suggest.

                  Write a Reply...