FTP/HTTP wrappers and and server test

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

FTP/HTTP wrappers and and server test

Post 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 :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: FTP/HTTP wrappers and and server test

Post 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.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: FTP/HTTP wrappers and and server test

Post 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";
    }
 
Post Reply