<commit_before><?php
/**
 * @package    CleverSyle CMS
 * @subpackage CleverStyle CMS Server
 * @author     <NAME> <<EMAIL>>
 * @copyright  Copyright (c) 2015, <NAME>
 * @license    MIT License, see license.txt
 */
/**
 * Before usage run:
 *
 * $ git clone <EMAIL>:reactphp/http.git
 * $ cd http
 * $ composer install
 */
require_once __DIR__.'/http/vendor/autoload.php';
$loop   = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http   = new React\Http\Server($socket);
// TODO: only first request handled currently, need more work in core
$http->on('request', function (\React\Http\Request $request, \React\Http\Response $response) {
	$request->on('data', function ($data) use ($request, $response) {
		$_SERVER = [];
		// TODO: Parse cookie header
		foreach ($request->getHeaders() as $key => $value) {
			if ($key == 'Content-Type') {
				$_SERVER['CONTENT_TYPE'] = $value;
			} else {
				$_SERVER['HTTP_'.strtoupper(strtr($key, '-', '_'))] = $value;
			}
		}
		$_SERVER['REQUEST_METHOD']  = $request->getMethod();
		$_SERVER['REQUEST_URI']     = $request->getPath();
		$_SERVER['QUERY_STRING']    = http_build_query($request->getQuery());
		$_GET                       = $request->getQuery();
		$_SERVER['SERVER_PROTOCOL'] = 'HTTP/'.$request->getHttpVersion();
		switch (explode(';', @$_SERVER['HTTP_'])) {
			case 'application/json':
				$_POST = json_decode($data, true);
				break;
			default:
				parse_str($data, $_POST);
		}
		ob_start();
		require_once __DIR__.'/index.php';
		shutdown_function();
		$headers = [];
		array_map(function ($header) use (&$headers) {
			$header              = explode(':', $header, 2);
			$headers[$header[0]] = ltrim($header[1]);
		}, headers_list());
		header_remove();
		$response->writeHead(200, $headers);
		$response->end(ob_get_clean());
	});
});

$socket->listen(9998);
$loop->run();
<commit_msg>Info about server starting<commit_after><?php
/**
 * @package    CleverSyle CMS
 * @subpackage CleverStyle CMS Server
 * @author     <NAME> <<EMAIL>>
 * @copyright  Copyright (c) 2015, <NAME>
 * @license    MIT License, see license.txt
 */
/**
 * Before usage run:
 * $ git clone <EMAIL>:reactphp/http.git
 * $ cd http
 * $ composer install
 *
 * Start server with:
 * $ php-cgi server.php
 */
require_once __DIR__.'/http/vendor/autoload.php';
$loop   = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http   = new React\Http\Server($socket);
// TODO: only first request handled currently, need more work in core
$http->on('request', function (\React\Http\Request $request, \React\Http\Response $response) {
	$request->on('data', function ($data) use ($request, $response) {
		$_SERVER = [];
		// TODO: Parse cookie header
		foreach ($request->getHeaders() as $key => $value) {
			if ($key == 'Content-Type') {
				$_SERVER['CONTENT_TYPE'] = $value;
			} else {
				$_SERVER['HTTP_'.strtoupper(strtr($key, '-', '_'))] = $value;
			}
		}
		$_SERVER['REQUEST_METHOD']  = $request->getMethod();
		$_SERVER['REQUEST_URI']     = $request->getPath();
		$_SERVER['QUERY_STRING']    = http_build_query($request->getQuery());
		$_GET                       = $request->getQuery();
		$_SERVER['SERVER_PROTOCOL'] = 'HTTP/'.$request->getHttpVersion();
		switch (explode(';', @$_SERVER['HTTP_'])) {
			case 'application/json':
				$_POST = json_decode($data, true);
				break;
			default:
				parse_str($data, $_POST);
		}
		ob_start();
		require_once __DIR__.'/index.php';
		shutdown_function();
		$headers = [];
		array_map(function ($header) use (&$headers) {
			$header              = explode(':', $header, 2);
			$headers[$header[0]] = ltrim($header[1]);
		}, headers_list());
		header_remove();
		$response->writeHead(200, $headers);
		$response->end(ob_get_clean());
	});
});

$socket->listen(9998);
$loop->run();

{'fraction_non_alphanumeric': 0.19868938401048492, 'fraction_numerical': 0.007339449541284404, 'mean_word_length': 3.8797953964194374, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1239330', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1266, 'n_words': 260}