Last active
November 22, 2023 11:36
-
-
Save Grendel7/acdb9075a2b5da1ad176591125f9f39b to your computer and use it in GitHub Desktop.
Test connection to a hostname and port with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
$domain = "smtp.gmail.com"; | |
$port = 587; | |
if ($socket = stream_socket_client("tcp://{$domain}:{$port}", $errno, $errstr, 10)) { | |
echo "stream_socket_client: Connection to {$domain}:{$port} successful!<br>"; | |
} else { | |
echo "stream_socket_client error ({$errno}): {$errstr}<br>"; | |
} | |
if (fsockopen($domain, $port)) { | |
echo "fsockopen: Connection to {$domain}:{$port} successful!<br>"; | |
} else { | |
echo "fsockopen error: ".error_get_last()['message']."<br>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment