I've got a live script which occasional has to retrieve a file via ftp,
download to the server, post-process it then display it.

I use caching to check to see if I've already got the file, but if I don't I
have to process the ftp_get operation which occasionally times out.

So, is it possible to trap the time limit exceeded error and return a fail
code?

For example:

function GetFileViaFTP( $filename )
{
    if (file_exists("cache/" . $filename))
    {
        return true;
    }

    $ftp = ftp_connect("some host");
    ftp_login($ftp, "some username", "some password");
    ftp_chdir($ftp, "some path");

    if (ftp_get($ftp, "cache/" . $filename, $filename, FTP_BINARY))  // This
will sometimes fail
    {
        ftp_quit($ftp);

        return true;
    }

    ftp_quit($ftp);

    return false;
}

function GetFile( $filename )
{
    if (file_exists("cache/" . $filename) || GetFileViaFTP($cache))
    {
        return file("cache/" . $filename);
    }

    return "Sorry, the file {$filename} could not be located";
}




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to