What are the differences between using ftp_connect and fsockopen for checking the status of an FTP server in PHP?

When checking the status of an FTP server in PHP, using ftp_connect is a simpler and more straightforward method compared to fsockopen. ftp_connect is specifically designed for FTP connections and handles the necessary setup and authentication automatically. On the other hand, fsockopen is a more general function for establishing network connections and requires manual handling of FTP commands.

// Using ftp_connect to check the status of an FTP server
$ftp_server = 'ftp.example.com';
$ftp_connection = ftp_connect($ftp_server);

if($ftp_connection){
    echo 'FTP server is online';
    ftp_close($ftp_connection);
} else {
    echo 'FTP server is offline';
}