memcached for php5.3.8

memcached for php5.3.8 下载

安装方法

命令行安装命令:
C:\{$path}\memcached.exe -d install
Windows下的Memcache安装:
1. 下载memcache的windows稳定版,解压放某个盘下面,比如在c:\memcached
2. 在终端(也即cmd命令界面)下输入 ‘c:\memcached\memcached.exe -d install’ 安装
3. 再输入: ‘c:\memcached\memcached.exe -d start’ 启动。NOTE: 以后memcached将作为windows的一个服务每次开机时自动启动。这样服务器端已经安装完毕了。
4.下载php_memcache.dll,请自己查找对应的php版本的文件
5. 在C:\winnt\php.ini 加入一行 ‘extension=php_memcache.dll’
6.重新启动Apache,然后查看一下phpinfo,如果有memcache,那么就说明安装成功!
memcached的基本设置:

-p 监听的端口
-l 连接的IP地址, 默认是本机
-d start 启动memcached服务
-d restart 重起memcached服务
-d stop|shutdown 关闭正在运行的memcached服务
-d install 安装memcached服务
-d uninstall 卸载memcached服务
-u 以的身份运行 (仅在以root运行的时候有效)
-m 最大内存使用,单位MB。默认64MB
-M 内存耗尽时返回错误,而不是删除项
-c 最大同时连接数,默认是1024
-f 块大小增长因子,默认是1.25
-n 最小分配空间,key+value+flags默认是48
-h 显示帮助

Memcache环境测试:
运行下面的php文件,如果有输出This is a test!,就表示环境搭建成功。开始领略Memcache的魅力把!
< ?php
$mem = new Memcache;
$mem->connect(’127.0.0.1′, 11211);
$mem->set(‘key’, ‘This is a test!’, 0, 60);
$val = $mem->get(‘key’);
echo $val;
?>

PHP统一计算UTF-8字符长度函数

尼玛,UTF8汉字三个字节,英文一个字节…必须统一!于是找了个这

function utf8_strlen($str) {
    $count = 0;
    for($i = 0; $i < strlen($str); $i++){
        $value = ord($str[$i]); //返回字符的ASCII值
        if($value > 127) {
            $count++;
            if($value >= 192 && $value <= 223) $i++;
            elseif($value >= 224 && $value <= 239) $i = $i + 2;
            elseif($value >= 240 && $value <= 247) $i = $i + 3;
            else die('Not a UTF-8 compatible string');
        }
        $count++;
    }
    return $count;
}

Sublime text2空格替换tab键

想换几个空格就敲几个空格键

sublime text配置快键键

sublime text配置快键键

{ "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "\t", "exact": true} },
{ "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "    ", "exact": false},
"context":
[
{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
]
},
{ "keys": ["tab"], "command": "reindent", "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": "    " },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
]
},

MySQL5.5即将面世,MySQL进入Oracle产品体系!

MySQL进入Oracle产品体系,获得了更多研发投入,新一代MySQL产品—MySQL5.5即将面世,较之之前的5.1版本,将获得诸多特性方面的提升,简单总结如下:

1. 默认存储引擎更改为InnoDB

InnoDB作为成熟、高效的事务引擎,目前已经广泛使用,但MySQL5.1之前的版本默认引擎均为MyISAM,此次MySQL5.5终于做到与时俱进,将默认数据库存储引擎改为InnoDB,并且引进了Innodb plugin 1.0.7。此次更新对数据库的好处是显而易见的:InnoDB的数据恢复时间从过去的一个甚至几个小时,缩短到几分钟(InnoDB plugin 1.0.7,InnoDB plugin 1.1, 恢复时采用红-黑树)。InnoDB Plugin 支持数据压缩存储,节约存储,提高内存命中率,并且支持adaptive flush checkpoint, 可以在某些场合避免数据库出现突发性能瓶颈。

Continue reading

PHP swfupload图片上传实例

swfupload已经是第二次研究,这次自已整了个简单demo,无奈菜鸟最杯…

PHP代码如下:

if (isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
	$upload_file = $_FILES['Filedata'];
	$file_info   = pathinfo($upload_file['name']);
	$file_type   = $file_info['extension'];
	$save        = 'image/' . md5(uniqid($_FILES["Filedata"]['name'])) . '.' . $file_info['extension'];
	$name        = $_FILES['Filedata']['tmp_name'];

	if (!move_uploaded_file($name, $save)) {
		exit;
	}

	//将数组的输出存起来以供查看
	$fileName = 'test.txt';
	$postData = var_export($file_info, true);
	$file     = fopen('' . $fileName, "w");
	fwrite($file,$postData);
	fclose($file);
}

实例包下载

山穷水尽之PHP正则匹配中文字母数字

主要是正则匹配!

$input_tag = $_POST['tag'];
$input_tag = explode(',', $input_tag);
$input_tag = array_unique($input_tag);
$input_tag = array_diff($input_tag, array(null));
$leng      = '';
$true      = '';
$comma     = '';

foreach ($input_tag as $v) {
	if (strlen($v) > 18) {
		$leng  .= $comma . $v;
		$comma = ',';
	}

	$true .= $comma . $v;
	$comma = ',';
}

$true = str_replace(',', '', $true);
if (!preg_match('/^[\x80-\xff_a-zA-Z0-9]+$/', $true)) {
	echo "<script>alert('不允许特殊符号的!!!');</script>";
	exit;
}

if (!empty($leng)) {
	echo "<script>alert('一个标签只能是6个汉字以内哦!!!');</script>";
	exit;
}