<commit_before><?php
/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/8/10
 * Time: 11:58
 */

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if(socket_connect($socket, "www.sina.com", 80) === false){
    echo "ERROR:" . socket_last_error($socket) . PHP_EOL;
    exit;
}

$request = <<<GLOB_MARK
GET / HTTP/1.1
Host: www.sina.com
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
GLOB_MARK;

$request .= PHP_EOL;


if(socket_write($socket, $request, strlen($request)) === false){
    echo "ERROR:" . socket_last_error($socket) . PHP_EOL;
    exit;
}

echo "we will get a error response because the request string is error." . PHP_EOL;
$response = socket_read($socket, 1024);
if($response === false){
    echo "ERROR:" . socket_last_error($socket);
    exit;
}
echo "response:" . PHP_EOL;
var_dump($response);


<commit_msg>添加HTTP客户端协议解析<commit_after><?php
/**
 * Created by PhpStorm.
 * User: Jenner
 * Date: 2015/8/10
 * Time: 11:58
 */

$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if(socket_connect($socket, "www.sina.com", 80) === false){
    echo "ERROR:" . socket_last_error($socket) . PHP_EOL;
    exit;
}

$request_headers = array(
    "GET / HTTP/1.1",
    "Host: www.sina.com",
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
);

$request = implode("\r\n", $request_headers);
$request .= "\r\n\r\n";

if(socket_write($socket, $request, strlen($request)) === false){
    echo "ERROR:" . socket_last_error($socket) . PHP_EOL;
    exit;
}

echo "we will get a error response because the request string is error." . PHP_EOL;
$response = socket_read($socket, 1024);
if($response === false){
    echo "ERROR:" . socket_last_error($socket);
    exit;
}
echo "response:" . PHP_EOL;
var_dump($response);



{'fraction_non_alphanumeric': 0.17911877394636017, 'fraction_numerical': 0.03735632183908046, 'mean_word_length': 4.4119170984455955, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 4}, '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': '3475301', 'n_tokens_mistral': 852, 'n_tokens_neox': 804, 'n_words': 166}