<commit_before>#!/usr/bin/php
<?php 

date_default_timezone_set('UTC');

$server = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr);
if (!$server) {
	echo "$errstr ($errno)<br />\n";
} else {
	$i = 0;
	while (true) {
		$socket = stream_socket_accept($server);
		if($socket) {	
			$request = stream_socket_recvfrom($socket, 1500);
			// parse the request 
			
			// return data based upon the request
			stream_socket_sendto($socket, 'Connection accepted from ' . stream_socket_get_name($socket, true) . "\n");
			stream_socket_sendto($socket, 'The local time is ' . date('n/j/Y g:i a') . "\n", STREAM_OOB);
			stream_socket_shutdown($socket, STREAM_SHUT_WR);
		}
		if($i++ > 10) break;
	}
	stream_socket_shutdown($server, STREAM_SHUT_WR);
}
?>
<commit_msg>Changed code, started to return images and parse headers<commit_after>#!/usr/bin/php
<?php 

date_default_timezone_set('UTC');

$server = stream_socket_server("tcp://0.0.0.0:8000", $errno, $errstr);
if (!$server) {
	echo "$errstr ($errno)<br />\n";
} else {
	while (true) {
		$socket = @stream_socket_accept($server);
		if($socket) {	
			$request = stream_socket_recvfrom($socket, 1500);
			if(!empty($request)) {
				$output		= '';
				$headers	= explode("\n",$request);
				if(is_array($headers)) { 
					// parse the request 
					for($i=0;$i<sizeof($headers);$i++) {
						if(strstr($headers[$i],':') !== FALSE) {
							list($headerType,$headerValue) = explode(':',$headers[$i]);
							$headerType		= trim($headerType); 
							$headerValue	= trim($headerValue);
						} else /*if ( strstr($headers[$i],'HTTP')) */{
							if(!empty($headers[$i])) { 
								switch(true) { 
									case strstr($headers[$i],'GET'):
									case strstr($headers[$i],'get'):
										preg_match('/\ (.*?)\ /',$headers[$i],$requestURI); 
										$requestURI = $requestURI[1];
										if ($requestURI == "/") {
											$requestURI = "/index.html";
										}
										$path = '/tmp/img';
										if (file_exists($path.$requestURI) && is_readable($path.$requestURI)) {
											$contents = file_get_contents($path.$requestURI);
											$mime			= "image/jpg";
											$output		= "HTTP/1.1 200 OK\r\nServer: PHPSocketServer\r\nConnection: close\r\nContent-Type: $mime\r\n\r\n$contents";
										} else {
											$contents = "The file you requested does not exist.";
											$output		= "HTTP/1.1 404\r\nServer: PHPSocketServer\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n$contents";
										}	
									break;
									case strstr($headers[$i],'POST'):
									case strstr($headers[$i],'post'):
										print_r($headers[$i].PHP_EOL);
										break;	
								default:
										break;
								}
							}
						}
					}
				}
				if(!empty($output)) { 
					// return data based upon the request
					$ret = stream_socket_sendto($socket, $output);
					print("Ret ".$ret.PHP_EOL);
					print("strlen ".strlen($output).PHP_EOL);
				}
			}
			stream_socket_shutdown($socket, STREAM_SHUT_RDWR);
		}
	}
	stream_socket_shutdown($server, STREAM_SHUT_RDWR);
}
?>

{'fraction_non_alphanumeric': 0.18774574049803408, 'fraction_numerical': 0.012778505897771953, 'mean_word_length': 2.8991060025542783, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2799472', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1077, 'n_words': 179}