<commit_before><?php

const HOST     = 'www.index.hu';
const PROTOCOL = 'icmp';
const COUNT    = 3;
const TIMEOUT  = 1;

$protocolNumber = getprotobyname(PROTOCOL);
$socket = socket_create(AF_INET, SOCK_RAW, $protocolNumber);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => TIMEOUT, 'usec' => 0));
socket_connect($socket, HOST, 0);

echo sprintf('PING %s (%s):', HOST, gethostbyname(HOST)) . PHP_EOL;

for ($i = 0; $i < COUNT; $i++) {
	$startTime = microtime(true);

	$package  = "\x08\x00\x19\x2f\x00\x00\x00\x00\x70\x69\x6e\x67";
	socket_send($socket, $package, strlen($package), 0);

	if (socket_read($socket, 255)) {
		printLine($i, $startTime);
	} else {
		$result = false;
	}
}

function printLine($seq, $startTime)
{
	echo sprintf('icmp_seq=%d time=%s', $seq, formatTime(microtime(true) - $startTime)) . PHP_EOL;
}

function formatTime($time)
{
	return sprintf('%.3f ms', round($time * 1000, 3));
}

socket_close($socket);<commit_msg>handle unknown host<commit_after><?php

const HOST     = 'index.hu';
const PROTOCOL = 'icmp';
const COUNT    = 3;
const TIMEOUT  = 1;

$ipAddress      = getIpAddress();
$protocolNumber = getprotobyname(PROTOCOL);
$socket         = socket_create(AF_INET, SOCK_RAW, $protocolNumber);
socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => TIMEOUT, 'usec' => 0));
socket_connect($socket, HOST, 0);

echo sprintf('PING %s (%s):', HOST, $ipAddress) . PHP_EOL;

for ($i = 0; $i < COUNT; $i++) {
	$startTime = microtime(true);

	$package  = "\x08\x00\x19\x2f\x00\x00\x00\x00\x70\x69\x6e\x67";
	socket_send($socket, $package, strlen($package), 0);

	if (socket_read($socket, 255)) {
		printLine($i, $startTime);
	} else {
		echo 'Request timed out.';
	}
}

function getIpAddress()
{
	$ipAddress = gethostbyname(HOST);
	if ($ipAddress === HOST) {
		echo sprintf('ping: cannot resolve %s: Unknown host', HOST) . PHP_EOL;
		exit();
	}

	return $ipAddress;
}

function printLine($seq, $startTime)
{
	echo sprintf('icmp_seq=%d time=%s', $seq, formatTime(microtime(true) - $startTime)) . PHP_EOL;
}

function formatTime($time)
{
	return sprintf('%.3f ms', round($time * 1000, 3));
}

socket_close($socket);
{'fraction_non_alphanumeric': 0.1866913123844732, 'fraction_numerical': 0.034195933456561925, 'mean_word_length': 5.030640668523677, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1099310', 'n_tokens_mistral': 921, 'n_tokens_neox': 866, 'n_words': 179}