Page 1 of 1

FTP/HTTP wrappers and and server test

Posted: Thu Mar 20, 2008 5:45 am
by alex.barylski
I'm using file_get_contents to retreive a file both FTP and HTTP -- depending on circumstances.

Sometimes the HTTP is down and I need to detemrine if the HTTP server is operating, otherwise resort to FTP.

I'm not looking to check server response via PING I need to know specifically if the http or ftp servers are up and running. Can this still be done via PING and the command line??? I have tried prefixing the IP with ftp: and http: and that didn't seem to work...

No extensions like sockets, cURL, etc -- please and thank you :)

Cheers :)

Re: FTP/HTTP wrappers and and server test

Posted: Thu Mar 20, 2008 8:47 am
by John Cartwright
My inexperience with servers shows a bit here, but I thought systems can be configured to ignore pinging. My colleagues and I have always opted for fsockopen() when determining if a service is online.

Re: FTP/HTTP wrappers and and server test

Posted: Thu Mar 20, 2008 11:43 pm
by yacahuma
Just read the url

Code: Select all

 
$html = implode('', file('http://www.example.com/'));
 
search for a particular string in the page. If is there, the web server is up(at least for the site your care)


for ftp, just use the the code example in php.net

Code: Select all

 
<?php
// set up basic connection
$conn_id = ftp_connect($ftp_server); 
 
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 
 
// check connection
if ((!$conn_id) || (!$login_result)) { 
        echo "FTP connection has failed!";
        echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
        exit; 
    } else {
        echo "Connected to $ftp_server, for user $ftp_user_name";
    }