V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  Tianpu  ›  全部回复第 24 页 / 共 25 页
回复总数  492
1 ... 16  17  18  19  20  21  22  23  24  25  
可以理解为类似标签的关系
2012-01-18 01:34:22 +08:00
回复了 muxi 创建的主题 分享发现 Mac下又一个编辑器神器 -- chocolat
世界上不可能有比ee更好的编辑器
2012-01-18 01:32:25 +08:00
回复了 imirrori 创建的主题 音乐 你最喜欢陈奕迅的哪首歌?
K歌之王
2012-01-05 16:43:34 +08:00
回复了 Tianpu 创建的主题 FreeBSD 开freebsd节点
其实用的人也不少哦 用上了就离不开的
2011-12-28 19:23:20 +08:00
回复了 caonimahexie 创建的主题 问与答 想把狗爹的域名转出来 不知哪个域名管理商靠谱
namesilo便宜
2011-12-28 01:04:17 +08:00
回复了 richiefans 创建的主题 问与答 对于站内搜索大家都是如何实现的?
@richiefans 记得给我小红花 www.xunsearch.com
2011-12-26 10:45:23 +08:00
回复了 Tianpu 创建的主题 PHP 纯php实现大文件全文搜索
我只是测试下php读取大文件的能力 实际结果非常满意 因此可以利用php做更多的事情了

我这边测试出来的是一次少量读取 迅速处理 然后PHP是具备处理大文件能力的 还有就是资源的节省很重要

感谢热心的vibbow 感谢所有参与本帖的人
2011-12-26 10:45:09 +08:00
回复了 Tianpu 创建的主题 PHP 纯php实现大文件全文搜索
还可以这样测试下 if(preg_match_all("/\\n(.*?)".$key."(.*?)\\n/i","\n".$str."\n",$match)) 行内匹配 无论如何不出结果都是没天理了
2011-12-26 10:32:30 +08:00
回复了 Tianpu 创建的主题 PHP 纯php实现大文件全文搜索
@vibbow 这个 用\n匹配的 按说没事 还有限制一次搜索结果在1M左右 最短是4字节 可能是被什么给限制了
2011-12-26 10:30:56 +08:00
回复了 Tianpu 创建的主题 PHP 纯php实现大文件全文搜索
@vibbow $r[3] = substr($temp,-60); 极少有一行超过60字节的 用这个临时数据来保证不遗漏 当然会有不好看的多余数据 理论上不会少
2011-12-26 05:24:39 +08:00
回复了 Tianpu 创建的主题 PHP 纯php实现大文件全文搜索
:) 我一次只读16k左右的一个块 这些因素应该已经规避了 可能是VPS烂吧 晚安啦
2011-12-26 05:15:53 +08:00
回复了 Tianpu 创建的主题 PHP 纯php实现大文件全文搜索
最终结果 天涯+csdn 6666条数据 返回113K的结果 耗时7.8s 还好了 睡觉
2011-12-26 04:27:29 +08:00
回复了 Tianpu 创建的主题 PHP 纯php实现大文件全文搜索
文件说明:
./x.php

data目录放入各种数据
./data/xxx.sql
./data/xxx.txt
./temp/

./temp需要写权限 用于保存用户临时数据

$files = array('csdn.sql'); 这里用数组调用各种数据

我还在测试 估计没有太多改进的余地了 毕竟磁盘IO是省不了的 基本运行也要点时间

欢迎提出改进意见
2011-12-26 04:24:12 +08:00
回复了 Tianpu 创建的主题 PHP 纯php实现大文件全文搜索
<?php
// error_reporting(0);
$time_start = getmicrotime();
session_start();
$key = $_GET['key'];
$time = $_GET['time'];
$files = array('csdn.sql');
$keyminlen = 4;
$step = 16000;
$limit = 1024000;
$lend = "\n";
$path = './temp/';
$data = './data/';
if($_GET['action']=='clear'){
unlink($path.$_SESSION['sid']);
$_SESSION['sid'] = '';
}
$sid = $_SESSION['sid'];
if($sid==''){
$sid = session_id();
$_SESSION['sid'] = $sid;
}
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function cache($file,$str){
global $sid,$path,$limit,$key,$time;
$ssize = filesize($path.$sid);
if($ssize>$limit){
echo "<a href=temp/$sid> result right click to save as</a><br>";
echo "<br><br><a href=?action=clear>get another keyword</a><br><br>processed in $time seconds";
die('too many result, contact us if you do need it');
}
if(preg_match_all("/(.*?)".$key."(.*?)\\n/i",$str,$match)){
if($ssize>0) file_put_contents($path.$sid,$match[0],FILE_APPEND);
else file_put_contents($path.$sid,$file."\n".$match[0],FILE_APPEND);
}
print_r(preg_last_error());
}
function large($file,$start,$repeat,$plus){
global $step,$data,$key;
$r = array();
$return = $temp = '';
$i = 0;
$handle = fopen($data.$file,'r');
while($i<$repeat && !feof($handle)){
fseek($handle, $start, SEEK_SET);
if($i==0) $temp = $plus.fread($handle,$step);
else $temp = fread($handle,$step);
if(strpos($temp,$key)){
$r[1].= $temp;
$r[2] = true;
$r[3] = substr($temp,-60);
}
$r[0]+= $step;
$start+= $step;
$i++;
}
fclose($handle);
return $r;
}
function process($file,$start,$lnum){
global $step,$lend,$fid,$time,$time_start,$key,$data;
$r = array();
$filesize = filesize($data.$file);
$block = 51200000;
$repeat = 10;
$tstr = '';
$count = 0;
while($count<$block && $start<$filesize){
$temp = large($file,$start,$repeat,$temp[3]);
$start+=$temp[0];
$count+=$temp[0];
if($temp[2]) cache($file,$temp[1]);
}
$time+=getmicrotime()-$time_start;
echo "<br><br>processed in $time seconds<br> continue<br ><br>";
if($start>=$filesize){
$fid++;
die($file.' KO.<br>continue to another<br><meta http-equiv="Refresh" content="0;url=?key='.rawurlencode($key).'&time='.$time.'&fid='.$fid.'">');
}
$r[] = $start;
$r[] = $lnum;
return $r;
}
$start = $_GET['start'];
$lnum = $_GET['lnum'];
$fid = $_GET['fid'];
if($fid<1) $fid = 0;
if($fid>count($files)-1){
if(filesize($path.$sid)>0){
echo "<a href=temp/$sid> result right click to save as</a><br>";
echo '<pre>'.file_get_contents($path.$sid).'</pre>';
}
else echo 'no result';
echo "<br><br><a href=?action=clear>get another keyword</a><br><br>processed in $time seconds";
die();
}
$file = $files[$fid];
if($key=='') die('<form>keyword: <input type=text name=key> <input type=submit></form>');
else{
if(strlen($key)<$keyminlen) die('keyword too short');
if($start<1) $start = 0;
if($lnum<2) $lnum = 1;
$t = process($file,$start,$lnum);
$time+=getmicrotime()-$time_start;
echo '<meta http-equiv="Refresh" content="0;url=?key='.rawurlencode($key).'&fid='.$fid.'&time='.$time.'&start='.$t[0].'&lnum='.$t[1].'&file='.$file.'">';
}
?>
是随便画三下 比如大 三 彡 氵都是可以的 或者干脆任意画个图形 比如三个同心圆
三亚不存在这样的地方
可以考虑去白沙啊什么的西海岸县城
2011-07-13 22:12:55 +08:00
回复了 levon 创建的主题 问与答 请推荐一款windows下的射击游戏吧,不要雷电
彩京+1
1 ... 16  17  18  19  20  21  22  23  24  25  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3609 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 30ms · UTC 04:46 · PVG 12:46 · LAX 21:46 · JFK 00:46
Developed with CodeLauncher
♥ Do have faith in what you're doing.