Archive for August, 2010
mysql 添加一个网段的用户权限支持
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’192.168.1.%’ IDENTIFIED BY ‘urpasswd’ WITH GRANT OPTION;
FLUSH PRIVILEGES;
‘root’@'%’ 是所有。。
xdebug profiler应用
相关文档在 http://www.xdebug.org/docs/profiler
wget 他的最新版本
tar -zxvf ***.tar.gz
/usr/local/php/bin/phpize && ./configure –with-php-config=/usr/local/php/bin/php-config && make && make install
xdebug.so出来以后,需要用zend加载
[Xdebug]
zend_extension=”/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so”
;xdebug.profiler_enable=on
xdebug.trace_output_dir=”/var/log/xdebug”
xdebug.profiler_output_dir=”/var/log/xdebug”
xdebug.profiler_enable_trigger=1
xdebug.profiler_append = 1
用了xdebug.profiler_enable_trigger=1 以后,就需要用cookie激活,不是每个php都输出文件了
setcookie(‘XDEBUG_PROFILE’,’1′);
要想看文件 装这个 http://code.google.com/p/webgrind/
这是个用php读xdebug的工具,很酷,很好用,设置一下debug的输出地址,就可以用了,非常简单。
重写php session (memcached)解决session 锁的问题
class SessionMemd {
private static $_sess;
private static $cas;
public static $maxlife = 3600;
private function __construct() {}
public static function open($save_path) {
self::$_sess = new Memcached();
$servers = explode(",",$save_path);
foreach($servers as &$v) {
if (preg_match('/[^:]*):(\d{4,5})/',$v,$match)) {
self::$_sess->addServer($match[1],$match[2]);
}
}
self::$_sess->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT);
self::$_sess->setOption(Memcached::OPT_HASH, Memcached::HASH_CRC);
return true;
}
public static function close() {
return true;
}
public static function read($id) {
return self::$_sess->get('sess_'.$id);
}
public static function write($id, $sess_data) {
return self::$_sess->set('sess_'.$id,$sess_data,self::$maxlife);
}
public static function destroy($id) {
return self::$_sess->delete('sess_'.$id);
}
public static function gc() {
return true;
}
}
SessionMemd::$maxlife = ini_get("session.gc_maxlifetime");
session_set_save_handler(array("SessionMemd","open"),array("SessionMemd","close"),array("SessionMemd","read"),array("SessionMemd","write"),array("SessionMemd","destroy"),array("SessionMemd","gc"));
register_shutdown_function ('session_write_close'); //必须调用这个,否则write_close函数不会被执行。。
include上面这个文件,并session_start() 即可rewrite 加锁的memcached session
这个函数有个问题,就是没有考虑session同斥共斥的问题,如果2个页面,一个快,一个慢,同时进行,慢的那个session修改会rewrite掉快的那个,不过这个比较少见!这种session使用的时候,特别是在写入session的时候,最好确认没有其他并行的session修改页面的存在。
php oracle模块安装
确定/home/oracle/10.2.0.3/client/ 目录下游oci.h文件
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –with-curl –with-zlib –enable-ftp –enable-inline-optimization –disable-debug –with-zlib –enable-xml –enable-soap –enable-zip –enable-mbstring –with-mhash –enable-mbstring –with-oci8=/home/oracle/10.2.0.3/client/
Makefile文件出来以后执行 sed -i ‘s#EXTRA_INCLUDES =#&-I/home/oracle/10.2.0.3/client/#’ Makefile
然后再make就能通过了。
安装mysql No curses/termcap library found 报错,最简单解决办法!
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
执行完这个,一切ok哇哈哈,太简单了!
mysql innodb 配置
启用innodb引擎,并配置相关参数
#skip-innodb innodb_additional_mem_pool_size = 16M #一般16M也够了,可以适当调整下 innodb_buffer_pool_size = 6G #如果是专用db的话,一般是内存总量的80% innodb_data_file_path = ibdata1:1024M:autoextend innodb_file_io_threads = 4 innodb_thread_concurrency = 20 innodb_flush_log_at_trx_commit = 1 innodb_log_buffer_size = 16M innodb_log_file_size = 256M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 50 innodb_lock_wait_timeout = 120 innodb_file_per_table
2. 修改表引擎为innodb
mysql> alter table cdb_access engine = innodb;
其他表类似上面,把表名换一下即可…
将表存储引擎改成innodb后,不仅可以避免大量的锁等待,还可以提升查询的效率,因为innodb会把data和index都放在buffer pool中,效率更高。
linux内核优化
nginx 文件漏洞
if ($request_filename ~* (.*)\.php) {
set $php_url $1;
}
if (!-e $php_url.php) {
return 403; Read the rest of this entry »
fast cgi vs nginx server_name的配置错误修正
fastcgi_param SERVER_NAME $host;
不要用$server_name 因为他不准,还是$host准!
Recent Comments