Professional Web Applications Themes

Testing if file exists on a web server - PHP Development

Hello, I am trying to efficiently detect if file exist at the specific URL where URL points to a completely different web server than where the script is being run at. I need constatnly check for a log file on another server and I need my script to detect that file there exists when the script checks for it. Right now I have the only way to see if file exists only by downloading the whole file with the following piece of code: ob_start(); $file = readfile($url); $contents = ob_get_contents(); ob_end_clean(); and see if read was empty or not. Problem ...

  1. #1

    Default Testing if file exists on a web server

    Hello,

    I am trying to efficiently detect if file exist at the specific URL where
    URL points to a completely different web server than where the script is
    being run at. I need constatnly check for a log file on another server and I
    need my script to detect that file there exists when the script checks for
    it. Right now I have the only way to see if file exists only by downloading
    the whole file with the following piece of code:

    ob_start();
    $file = readfile($url);
    $contents = ob_get_contents();
    ob_end_clean();

    and see if read was empty or not. Problem is that if the log will happen to
    be a few megs then the alarm will be delayes since it will take a few mins
    to download the whole file first. Is there a more efficient way to check for
    existence of the file on the remote webserver without downloading the file
    and checking for the length?

    I'd take any idea you might have. Thanks.


    Hello Guest

  2. #2

    Default Re: Testing if file exists on a web server

    On Sat, 09 Jul 2005 03:27:21 GMT, "Hello" <com> wrote:
     
    Does
    http://uk2.php.net/manual/en/function.file-exists.php
    help?
    nemo Guest

  3. #3

    Default Re: Testing if file exists on a web server

    No, that function can only be applied to a same server where the script is
    being run off, it will not do anything to a remote server.

    After thinking a bit, I came up with this code (some parts were removed for
    clarity):

    $handle = fopen($url, 'r');
    if ($handle===false) { //not on server }
    else fclose($handle); //on server

    If anyone has any ideas or other ways, I am all ears.

    Thanks.


    "nemo" <com> wrote in message
    news:com... 
    > where 
    > is 
    > and I 
    > for 
    > downloading 
    > happen to 
    > mins 
    > check for 
    > file 
    > Does
    > http://uk2.php.net/manual/en/function.file-exists.php
    > help?[/ref]


    Hello Guest

  4. #4

    Default Re: Testing if file exists on a web server

    Hello wrote:
     
     [/ref]

    HTTP provides for this (HEAD). IIRC this is not directly accessible via the
    the file wrappers. It is possible via the command line version of curl - so
    I'm guessing it's possible with libcurl too.

    HTH

    C.
    Colin Guest

Similar Threads

  1. Testing if a value exists.
    By Andy Levy in forum PHP Development
    Replies: 3
    Last Post: October 30th, 11:03 AM
  2. Testing if a mysql table exists
    By sam in forum PHP Development
    Replies: 1
    Last Post: October 16th, 11:10 PM
  3. Testing whether a subroutine exists (symbolic ref)
    By Richard Voss in forum PERL Miscellaneous
    Replies: 5
    Last Post: September 4th, 12:25 PM
  4. file.exists and security on windows 2003 server
    By naz in forum ASP.NET Security
    Replies: 0
    Last Post: August 6th, 02:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139