Question

I have a few ftp servers that I manage for an engineering company. Some of these ftp servers are set-up as data back-up severs through a php interface. I do maintenance twice a day whereby I stop the ftp daemon (proftpd) on the ftp server I am doing maintenance on.

However, one of the requirements for the php app to work is to log into each ftp server, download a statistics file (which is mailed to the CEO). Currently if proftpd is stopped on any of the ftp servers, and the php app is running, php hangs (via the browser) while trying to log into the (stopped) ftp server.

I have set the timeout to 90 (default) seconds down to 5 seconds, but the same thing happens.

How can I prevent php from hanging the browser while php is doing login on the stopped ftp server?

Any pointers?

Thank You

Danny

Was it helpful?

Solution

You could do a pre check with fsockopen() and store its connection state in session (so as to not do the check on every reload).

<?php 
session_start();

if(!isset($_SESSION['ftp_connectable'])){
    $sock = @fsockopen('ftp.yourserver', 21, $errno, $errstr, 1);//< 1sec timeout
    if ($sock) {
        $_SESSION['ftp_connectable'] = true;
    }else{
        $_SESSION['ftp_connectable'] = false; 
    }
    @fclose($sock);
}

if($_SESSION['ftp_connectable'] === true){
    echo '<span style="color:red">FTP Server is connectable!</span>';
}else{
    echo '<span style="color:red">FTP Server is not connectable!</span>';
}

Then show a notice the server is down based on $_SESSION['ftp_connectable'] you can add a Try Again button that clears the $_SESSION['ftp_connectable'] variable and try's the connection state again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top