function socket($host, $url, $content, $port = 80) {
$data = “POST ” . $url . ” HTTP/1.1\r\n”;
$data .= “Host: ” . $host . “\r\n”;
$data .= “Content-Type: application/x-www-form-urlencoded\r\n”;
$data .= “Content-Length: ” . strlen($content) . “\r\n”;
$data .= “\r\n”;
$data .= $content . “\r\n\r\n”;
$ock = fsockopen($host, $port);
if (!$ock) {
echo ‘No response from ‘ . $host . “\n”;;
}
fwrite($ock, $data);
$r = “”;
while (!feof($ock)) {
$r .= fgets($ock, 1024);
}
preg_match(“/(\{.+\})/”, $r, $m);
fclose($ock);
return $m[1];
}
function socket_by_curl($host, $url, $content, $port = 80) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host.$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/x-www-form-urlencoded’));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($ch);
curl_close($ch);
preg_match(“/(\{.+\})/”, $r, $m);
return $m[1];
}

Categories: 感悟 Tags:

linux批量解压rar到各自文件夹0+

5,341 views / 2014.01.12 / 10:10 下午

相信用过winrar的朋友都不陌生,在windows下面一次选取多个压缩文件,点右键会弹出解压每个压缩文件到单独的文件夹,这个给一次解压多个文件非常方便。在linux系统下的实现过程如下:

for i in `ls *.rar`
do
mkdir ./${i/.rar//}
unrar x $i ${i/.rar//}
done

Categories: 感悟 Tags: