Last Updated: February 25, 2016
·
16.75K
· ganey

Check if a port is open with PHP

The following function returns true / false if a port is open with PHP.

function stest($ip, $portt) {
    $fp = @fsockopen($ip, $portt, $errno, $errstr, 0.1);
    if (!$fp) {
        return false;
    } else {
        fclose($fp);
        return true;
    }
}