摘要: 去年纠结了很久,找了很多代码,也很了很多很多代码,也用了libevent,中间还转了python,都没有能实现一个支持高并发的socket服务程序下面的代码已经在在线环境测试了8天了,负载可以忽略,贡献出来,给我一样曾经迷惑的人:其中不少是借鉴的某大侠的代码,只是不记得地址了,就不写了#include <stdio.h>#include <unistd.h>#include <string.h>#include <stdlib.h>#include <sys/epoll.h>#include <sys/types.h>#i 阅读全文
posted @ 2011-03-04 16:12 MultiThread-PHP 阅读(2391) 评论(0) 推荐(1) 编辑
摘要: mysql> CREATE PROCEDURE `NewProcedure`(in int_role_id int(11)) -> BEGIN -> declare str_sql,str_h1,str_camp1 varchar(100) default ''; -> declare int_1 ,int_tmp int(11) default 0; -> select @int_role_id,@int_tmp,int_role_id,int_tmp; -> SET int_tmp=1; -> select @int_role_id 阅读全文
posted @ 2011-03-03 11:58 MultiThread-PHP 阅读(296) 评论(0) 推荐(0) 编辑
摘要: 使用Valgrind 查找内存泄露2010-04-16 21:17Valgrind 已经在 Linux 应用程序开发社区中广泛用来调试应用程序。它尤其擅长发现内存管理的问题。它可以检查程序运行时的内存泄漏问题。这个工具目前正由 Julian Seward 进行开发,并由 Paul Mackerras 移植到了 Power 架构上。要安装 Valgrind,请从 Valgrind 的 Web 站点上下载源代码(参阅参考资料)。切换到 Valgrind 目录,并执行下面的命令:# make# make check# make installValgrind 的错误报告Valgrind 的输出格式如 阅读全文
posted @ 2010-12-15 10:08 MultiThread-PHP 阅读(4471) 评论(0) 推荐(0) 编辑
摘要: c: zval *argvs[2]; zval *func; MAKE_STD_ZVAL(func); MAKE_STD_ZVAL(argvs[0]); MAKE_STD_ZVAL(argvs[1]); ZVAL_LONG(argvs[0], 317); ZVAL_STRING(argvs[1], "Lein's birthday is ",1); ZVAL_STRING(func, "callme",1); if (call_user_function(EG(function_table), NULL, func, &retval, 2 阅读全文
posted @ 2010-12-13 12:21 MultiThread-PHP 阅读(539) 评论(0) 推荐(0) 编辑
摘要: 其一,操作memcache服务器,<?php class mem{ private static $conn; public function mem($host='127.0.0.1',$port=11211) { $conn = new Memcache; $conn->pconnect($host, $port); } public function get($key) { return $this->conn->get($key); } public function set($key,$value,$expire=259200) { retur 阅读全文
posted @ 2010-10-04 18:29 MultiThread-PHP 阅读(238) 评论(0) 推荐(0) 编辑
摘要: <?php function aes128cbcEncrypt($key, $text) { /* Open the cipher */ $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); if (! $td) { throw new GeneralSecurityException('Invalid mcrypt cipher, check your libmcrypt library and php-mcrypt extention'); } / 阅读全文
posted @ 2010-09-26 14:04 MultiThread-PHP 阅读(3026) 评论(0) 推荐(0) 编辑
摘要: php 的 libevent库,到pecl找<?phpclass epoll{ private static $socket; private static $connections; private static $buffers; function epoll($port){ if($port<1024) die("Port must be a number which bigger than 1024/n"); self::$socket = stream_socket_server ('tcp://0.0.0.0:'.$port, $.. 阅读全文
posted @ 2010-08-30 15:19 MultiThread-PHP 阅读(674) 评论(1) 推荐(0) 编辑
摘要: 网上有很多的文章教怎么配置MySQL服务器,但考虑到服务器硬件配置的不同,具体应用的差别,那些文章的做法只能作为初步设置参考,我们需要根据自己的情况进行配置优化,好的做法是MySQL服务器稳定运行了一段时间后运行,根据服务器的”状态”进行优化。mysql> show global status;可以列出MySQL服务器运行各种状态值,另外,查询MySQL服务器配置信息语句:mysql> show variables;一、慢查询mysql> show variables like '%slow%';+------------------+-------+| Va 阅读全文
posted @ 2010-08-20 12:49 MultiThread-PHP 阅读(1025) 评论(0) 推荐(0) 编辑
摘要: Table_locks_immediate表示立即释放表锁数,Table_locks_waited表示需要等待的表锁数,如果Table_locks_immediate / Table_locks_waited > 5000,最好采用InnoDB引擎,因为InnoDB是行锁而MyISAM是表锁,对于高并发写入的应用InnoDB效果会好些。示例中的服务器Table_locks_immediate / Table_locks_waited = 235,MyISAM就足够了。 mysql> show status like 'table%';+--------------- 阅读全文
posted @ 2010-08-20 10:11 MultiThread-PHP 阅读(208) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <string.h>#include <stdlib.h>main(int argc, char **argv){ char *bufP=malloc(128); strcpy(bufP,(char *)argv[1]); printf("dir=%s/n",bufP); printf("argv[1]=%s/n",(char *)argv[1]); char *ROOT=malloc(256); memset(ROOT,0,256); pr... 阅读全文
posted @ 2010-07-04 11:53 MultiThread-PHP 阅读(742) 评论(1) 推荐(0) 编辑