mirror of https://github.com/YGGverse/net-php.git
composernetworkipv6network-apiipv4dnsdns-resolver-apiphp-resolverdignet-phpdns-php-libraryphp-digdns-php
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
![]()
7 months ago
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace Yggverse\Net;
|
||
|
|
||
![]()
7 months ago
|
class Socket
|
||
![]()
7 months ago
|
{
|
||
|
public static function isHost(mixed $value): bool
|
||
|
{
|
||
|
return
|
||
|
(
|
||
|
is_string($value) &&
|
||
|
(
|
||
|
false !== filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ||
|
||
|
false !== filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ||
|
||
|
false !== filter_var($value, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
public static function isPort(mixed $value): bool
|
||
|
{
|
||
|
$length = strlen(
|
||
|
$value
|
||
|
);
|
||
|
|
||
|
return false !== filter_var($value, FILTER_VALIDATE_INT) && 0 < $length && 65536 > $length;
|
||
|
}
|
||
|
|
||
|
public static function isOpen(string $host, int $port = -1, ?float $timeout = null, int &$error_code = null, string &$error_message = null): bool
|
||
|
{
|
||
|
return is_resource(
|
||
|
@fsockopen(
|
||
|
$host,
|
||
|
$port,
|
||
|
$error_code,
|
||
|
$error_message,
|
||
|
$timeout
|
||
|
)
|
||
|
);
|
||
|
}
|
||
|
}
|