Warning: curl_exec() has been disabled for security reasons in /pub/host/sunboyu/sunboyu/www/wp-includes/http.php on line 1022

Warning: Cannot modify header information - headers already sent by (output started at /pub/host/sunboyu/sunboyu/www/wp-includes/http.php:1022) in /pub/host/sunboyu/sunboyu/www/wp-includes/feed-rss2.php on line 8
一个程序猿 » mysql http://www.sunboyu.cn 时光不会倒流,脚步总要前进 Tue, 31 Jan 2012 10:50:34 +0000 http://wordpress.org/?v=2.7 en hourly 1 mysql_udf_tc 未测试发布版 http://www.sunboyu.cn/2011/03/18/mysql_udf_tc-%e6%9c%aa%e6%b5%8b%e8%af%95%e5%8f%91%e5%b8%83%e7%89%88.shtml http://www.sunboyu.cn/2011/03/18/mysql_udf_tc-%e6%9c%aa%e6%b5%8b%e8%af%95%e5%8f%91%e5%b8%83%e7%89%88.shtml#comments Fri, 18 Mar 2011 03:11:39 +0000 admin http://www.sunboyu.cn/?p=1397 受伤了,没时间折腾,先发布未测试版,欢迎各种bug提交,康复后继续

mysql数据同步到tc的table表,直接写文件,php读文件查询。

看手册,不解释。

有问题加qq 176300676

  1. #ifdef STANDARD
  2. #include <stdlib .h>
  3. #include <stdio .h>
  4. #include <string .h>
  5. #ifdef __WIN__
  6. typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
  7. typedef __int64 longlong;
  8. #else
  9. typedef unsigned long long ulonglong;
  10. typedef long long longlong;
  11. #endif /*__WIN__*/
  12. #else
  13. #include <my_global .h>
  14. #include <my_sys .h>
  15. #include <m_string .h>
  16. #endif
  17. #include <mysql .h>
  18. #include <ctype .h>
  19.  
  20. #include <float .h>
  21.  
  22.  
  23. #include <tcutil .h>
  24. #include <tctdb .h>
  25. #include <stdlib .h>
  26. #include <stdbool .h>
  27. #include <stdint .h>
  28.  
  29.  
  30.  
  31. #ifdef HAVE_DLOPEN
  32.  
  33. /*   TC_CREATE    */
  34. my_bool tc_create_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
  35. {
  36. return 0;
  37. }
  38.  
  39. void tc_create_deinit(UDF_INIT *initid)
  40. {
  41. }
  42.  
  43. char * tc_create(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error)
  44. {
  45. TCTDB *tdb;
  46. int ecode;
  47.     char *errormsg;
  48. char *tcfile;
  49. tdb = tctdbnew();
  50.  
  51. tcfile = args->args[0];
  52.  
  53.     /* open the database */
  54.     if(!tctdbopen(tdb, tcfile, TDBOWRITER | TDBOCREAT))
  55. {
  56.         ecode = tctdbecode(tdb);
  57.         sprintf(errormsg, "error: %s\n", tctdberrmsg(ecode));
  58.  
  59.     }
  60. else
  61. {
  62. sprintf(errormsg, "OK");
  63. }
  64. *length = strlen(errormsg);
  65. return errormsg;
  66. }
  67.  
  68. /*   TC_SET    */
  69. my_bool tc_set_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
  70. {
  71.   if (args->arg_count < 3)
  72.   {
  73.     strcpy(message,"Wrong arguments to metaphon;  Use the source");
  74.     return 1;
  75.   }
  76.   return 0;
  77. }
  78.  
  79.  
  80. void tc_set_deinit(UDF_INIT *initid)
  81. {
  82. }
  83.  
  84.  
  85. char *tc_set(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error)
  86. {
  87. char *dbfile,*errormsg,pkbuf[200];
  88. TCTDB *tdb;
  89. TCMAP *cols;
  90. int i = 0;
  91. int ecode,pksiz;
  92.     memcpy(result, "result string", 13);
  93.     *length = 13;
  94.  
  95. dbfile = args->args[0];
  96.  
  97. tdb = tctdbnew();
  98.  
  99.     if(!tctdbopen(tdb, dbfile, TDBOWRITER | TDBOCREAT)){
  100.         ecode = tctdbecode(tdb);
  101.         sprintf(errormsg, "open error: %s\n", tctdberrmsg(ecode));
  102.     }
  103.  
  104. cols = tcmapnew();
  105.  
  106. for(i = 2;i<args ->arg_count;i++)
  107. {
  108. tcmapput2(cols, args->attributes[i], args->args[i]);
  109. }
  110. pksiz = sprintf(pkbuf,"%s",args->attributes[1]);
  111. if(!tctdbput(tdb, pkbuf, pksiz, cols)){
  112.         ecode = tctdbecode(tdb);
  113.         sprintf(errormsg,"put error: %s\n", tctdberrmsg(ecode));
  114.  
  115.     }
  116. else
  117. {
  118. errormsg = "OK";
  119.  
  120. }
  121.     tcmapdel(cols);
  122.  
  123. if(!tctdbclose(tdb)){
  124.         ecode = tctdbecode(tdb);
  125.         sprintf(errormsg, "close error: %s\n", tctdberrmsg(ecode));
  126.     }
  127. *length = strlen(errormsg);
  128. return errormsg;
  129. }
  130.  
  131. /*   TC_DEL    */
  132. my_bool tc_del_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
  133. {
  134.   if (args->arg_count < 2)
  135.   {
  136.     strcpy(message,"Wrong arguments to metaphon;  Use the source");
  137.     return 1;
  138.   }
  139.   return 0;
  140. }
  141. void tc_del_deinit(UDF_INIT *initid)
  142. {
  143. }
  144. char * tc_del(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error)
  145. {
  146. TCTDB *tdb;
  147. char *dbfile,*errormsg,*pkbuf;
  148. int ecode;
  149.  
  150. dbfile = args->args[0];
  151. pkbuf = args->args[1];
  152.  
  153. tdb = tctdbnew();
  154.  
  155.     if(!tctdbopen(tdb, dbfile, TDBOWRITER | TDBOCREAT)){
  156.         ecode = tctdbecode(tdb);
  157.         sprintf(errormsg, "open error: %s\n", tctdberrmsg(ecode));
  158.     }
  159. if(!tctdbout2(tdb,pkbuf))
  160. {
  161. ecode = tctdbecode(tdb);
  162.         sprintf(errormsg,"delete error: %s\n", tctdberrmsg(ecode));
  163. }
  164. else
  165. {
  166. errormsg = "OK";
  167. }
  168. if(!tctdbclose(tdb)){
  169.         ecode = tctdbecode(tdb);
  170.         sprintf(errormsg, "close error: %s\n", tctdberrmsg(ecode));
  171.     }
  172. *length = strlen(errormsg);
  173. return errormsg;
  174.  
  175. }
  176. /*   TC_SETINDEX    */
  177. my_bool tc_sexindex_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
  178. {
  179.   if (args->arg_count < 2)
  180.   {
  181.     strcpy(message,"Wrong arguments to metaphon;  Use the source");
  182.     return 1;
  183.   }
  184.   return 0;
  185. }
  186. void tc_sexindex_deinit(UDF_INIT *initid)
  187. {
  188. }
  189. char * tc_sexindex(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error)
  190. {
  191. TCTDB *tdb;
  192. char *dbfile,*errormsg,*pkname[200];
  193. int ecode,indextype;
  194.  
  195. dbfile = args->args[0];
  196. *pkname = args->attributes[1];
  197.  
  198. tdb = tctdbnew();
  199.  
  200.     if(!tctdbopen(tdb, dbfile, TDBOWRITER | TDBOCREAT)){
  201.         ecode = tctdbecode(tdb);
  202.         sprintf(errormsg, "open error: %s\n", tctdberrmsg(ecode));
  203.     }
  204.     if(args->args[2]=="string")
  205. {
  206. indextype = TDBITLEXICAL;
  207. }
  208. else if(args->args[2]=="int")
  209. {
  210. indextype = TDBITDECIMAL;
  211. }
  212. if(!tctdbsetindex(tdb,*pkname,indextype))
  213. {
  214. ecode = tctdbecode(tdb);
  215.         sprintf(errormsg, "setindex error: %s\n", tctdberrmsg(ecode));
  216. }
  217.  
  218. if(!tctdbclose(tdb)){
  219.         ecode = tctdbecode(tdb);
  220.         sprintf(errormsg, "close error: %s\n", tctdberrmsg(ecode));
  221.     }
  222. *length = strlen(errormsg);
  223. return errormsg;
  224. }
  225. #endif /* HAVE_DLOPEN */
  226. </args></stdint></stdbool></stdlib></tctdb></tcutil></float></ctype></mysql></m_string></my_sys></my_global></string></stdio></stdlib>

编译安装脚本,自理

  1. #!/bin/sh
  2. gcc -Wall -I/opt/mysql-5.0.22/include/mysql -I/opt/tokyocabinet-1.4.46/include -I. -shared -L/usr/lib -ltokyocabinet -lz -lbz2 -lrt -lpthread -lm -lc  udf_tt.c -o lib_mysqludf_tt.so
  3. #gcc -Wall -I/opt/mysql-5.0.22/include/mysql -I. -static udf_tt.c -o lib_mysqludf_tt.so
  4. cp -f ./lib_mysqludf_tt.so /usr/lib/lib_mysqludf_tt.so
  5. service mysqld restart

使用:

  1. drop function tc_create;
  2. create function tc_create returns string soname 'lib_mysqludf_tt.so';
  3.  
  4. drop function tc_set;
  5. create function tc_set returns string soname 'lib_mysqludf_tt.so';
  6.  
  7. select tc_set("/home/sunboyu/test",`User`,`Host`) FROM user limit 1
]]>
http://www.sunboyu.cn/2011/03/18/mysql_udf_tc-%e6%9c%aa%e6%b5%8b%e8%af%95%e5%8f%91%e5%b8%83%e7%89%88.shtml/feed
利用udf扩展mysql增加json_object函数 http://www.sunboyu.cn/2011/01/23/%e5%88%a9%e7%94%a8udf%e6%89%a9%e5%b1%95mysql%e5%a2%9e%e5%8a%a0json_object%e5%87%bd%e6%95%b0.shtml http://www.sunboyu.cn/2011/01/23/%e5%88%a9%e7%94%a8udf%e6%89%a9%e5%b1%95mysql%e5%a2%9e%e5%8a%a0json_object%e5%87%bd%e6%95%b0.shtml#comments Sun, 23 Jan 2011 13:47:57 +0000 admin http://www.sunboyu.cn/?p=1378 其实已经有一个成形的mysql json编码的模块 http://www.mysqludf.org/lib_mysqludf_json/index.php

不过我们在使用的过程中,发现这个函数有版本兼容的问题,后看代码,发现它的json加密规则比较麻烦,没拆出来分析,就自己使用一个json类 http://sourceforge.net/projects/cjson/ 重写了一遍json_object函数。

目前在mysql-5.0.22版本上使用基本没问题,但在mysql5.5以上版本会有问题,udf接口格式好像有了变化。

mysql-5.0.22版本给出的例子是c++的代码。使用了extern语法,为了兼容gcc的语法。而我实际使用纯C环境,就抛弃了extern的语法。

udf_json源码下载

  1. file:udf_json.c
  2. #ifdef STANDARD
  3. #include <stdlib .h>
  4. #include <stdio .h>
  5. #include <string .h>
  6. #ifdef __WIN__
  7. typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
  8. typedef __int64 longlong;
  9. #else
  10. typedef unsigned long long ulonglong;
  11. typedef long long longlong;
  12. #endif /*__WIN__*/
  13. #else
  14. #include <my_global .h>
  15. #include <my_sys .h>
  16. #include <m_string .h>
  17. #endif
  18. #include <mysql .h>
  19. #include <ctype .h>
  20. #include <float .h>
  21. #include "cJSON.h"
  22. #ifdef HAVE_DLOPEN
  23. my_bool json_object_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
  24. {
  25.   if (args->arg_count < 1)
  26.   {
  27.     strcpy(message,"Wrong arguments to metaphon;  Use the source");
  28.     return 1;
  29.   }
  30.   return 0;
  31. }
  32. void json_object_deinit(UDF_INIT *initid)
  33. {
  34. }
  35. char *json_object(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error)
  36. {
  37. cJSON *root;
  38. char *out;
  39. int i = 0;
  40.  
  41. root=cJSON_CreateObject();
  42. for(i = 0;i<args->arg_count;i++)
  43. {
  44. if(args->arg_type[i] == STRING_RESULT)
  45. {
  46.     cJSON_AddStringToObject(root, args->attributes[i], args->args[i]);
  47. }
  48. else if(args->arg_type[i] == INT_RESULT)
  49. {
  50. cJSON_AddNumberToObject(root, args->attributes[i], *((int*)args->args[i])); //函数参数为double型,这里强转int是好使的,纳闷
  51. }
  52. }
  53. out=cJSON_Print(root);
  54.     cJSON_Delete(root);
  55. *length = strlen(out);
  56. return out;
  57. }
  58. #endif /* HAVE_DLOPEN */
  59.  
  60. file:make.sh
  61. #!/bin/sh
  62. gcc -Wall -I/opt/mysql-5.0.22/include/mysql -I. -shared udf_json.c cJSON.c -o lib_mysqludf_json.so
  63. cp -f ./lib_mysqludf_json.so /usr/lib/lib_mysqludf_json.so
  64. service mysqld restart
  65. </float></ctype></mysql></m_string></my_sys></my_global></string></stdio></stdlib>

编译完成,复制so文件至公共库,然后执行以下语句:

  1. drop function json_object;
  2. create function json_object returns string soname 'lib_mysqludf_json.so';

使用 :

  1. SELECT json_object(field1,field2……) AS jsdate FROM table;

PHP调用:

  1. $db = mysql_connect("127.0.0.1:3306","root","123456");
  2. mysql_select_db("test");
  3. $query = mysql_query("SELECT json_object(id,intval,value) FROM test LIMIT 6");
  4. while($row = mysql_fetch_array($query)){
  5.     var_dump(json_decode($row[0],true));
  6. }

结果显示:

array(3) {
["id"]=>
int(2)
["intval"]=>
int(43324)
["value"]=>
string(10) “fdsfdsfdsa”
}
array(3) {
["id"]=>
int(5)
["intval"]=>
int(432432432)
["value"]=>
string(10) “fdsafdsasa”
}

]]>
http://www.sunboyu.cn/2011/01/23/%e5%88%a9%e7%94%a8udf%e6%89%a9%e5%b1%95mysql%e5%a2%9e%e5%8a%a0json_object%e5%87%bd%e6%95%b0.shtml/feed
利用loadrunner做mysql压力测试 http://www.sunboyu.cn/2011/01/06/%e5%88%a9%e7%94%a8loadrunner%e5%81%9amysql%e5%8e%8b%e5%8a%9b%e6%b5%8b%e8%af%95.shtml http://www.sunboyu.cn/2011/01/06/%e5%88%a9%e7%94%a8loadrunner%e5%81%9amysql%e5%8e%8b%e5%8a%9b%e6%b5%8b%e8%af%95.shtml#comments Thu, 06 Jan 2011 15:05:07 +0000 admin http://www.sunboyu.cn/?p=1354 loadrunner下的mysql c api

一个很简单的模拟用户访问论坛帖子的loadrunner测试脚本

最近跟测试组学习loadrunner的使用,测试组的姑娘们习惯用界面进行操作,而习惯linux平台使用的我很多功能都使用代码来实现了。

最近用loadrunner写了一个模拟社区用户压测论坛数据库的一个脚本,进行数据库的压力测试和优化工作。

用户行为分析:

在社区中,看帖的人是发帖人的10倍以上,而看帖人大概80%以上都在看新帖,20以下的用户有挖坟行为。

因此,设定如此的比率:每11个用户,1个发帖,8个看最近30%的帖,两个看老的70%的帖。

我的论坛帖子回复表大概是:973505个帖子的回复,两千多万的回帖。

根据这些数据,配合mysql的c api,写如下脚本:

注:脚本的my_mysql_insert()函数是有问题的,多线程下有一个资源符没处理好,因为还不太了解loadrunner的线程机制,所以留下了一个bug。

在做完这个脚本后,我发现我们测试机性能都不错,很难在一个5G大小的单表上主键查询造成很大的压力,所以,计划把dz论坛架设,用php+mysql真实环境下进行压测,这样可以顺便练习http函数下的loadrunner编程。

  1. globals.h
  2. #ifndef _GLOBALS_H
  3. #define _GLOBALS_H
  4. #include "lrun.h"
  5. #include "web_api.h"
  6. #include "lrw_custom_body.h"
  7. #include "modal_dialog_callbacks.h"
  8. #define random(x) (rand()%x)
  9. #include <mysql .h>
  10. #include <mysql_com .h>
  11. #include <mysql_time .h>
  12. #include <mysql_version .h>
  13. #include <typelib .h>
  14. #include <my_list .h>
  15. #include <my_alloc .h>
  16. #endif // _GLOBALS_H
  17. </my_alloc></my_list></typelib></mysql_version></mysql_time></mysql_com></mysql>
  1. vuser_init.c
  2. MYSQL *db;
  3. MYSQL_ROW record;
  4. vuser_init()
  5. {
  6. char sql[128];
  7. MYSQL_RES *results1;
  8.     lr_load_dll("libmysql.dll");
  9.     db = mysql_init(NULL);
  10. mysql_real_connect(db, "192.168.8.32", "root", "123456", "sunboyu_test", 3311, "/tmp/mysql3311.sock", 1);
  11.     
  12. sprintf(sql, "show tables");
  13. mysql_query(db, sql);
  14.     results1 = mysql_store_result(db);
  15.     while((record = mysql_fetch_row(results1)))
  16. {
  17.     lr_log_message("table = %s", record[0]);
  18.      }
  19. mysql_free_result(results1);
  20. return 0;
  21. }
  1. vuser_end.c
  2. vuser_end()
  3. {
  4.    mysql_close(db);
  5.    mysql_server_end();
  6. return 0;
  7. }
  1. Action.c
  2. Action()
  3. {
  4. int r1 = 0;
  5. char sql[128];
  6. r1 = random(11);            //10种用户,8种正常访问,两种在挖坟
  7. lr_log_message(" %d", r1);
  8.         if(r1==11)
  9.         {
  10.             my_mysql_insert();
  11.         }
  12.         else
  13.         {
  14.             my_mysql_query( r1 );
  15.         }
  16. return 0;
  17. }
  18.  
  19. int my_mysql_query( int randid )
  20. {
  21. int r2 = 0;
  22. int j = 0;
  23. int count = 0;
  24. int page = 0;
  25. char sql[128];
  26. MYSQL_RES *results2;
  27. if(randid&lt;2)  //老数据,小部分 20%
  28. {
  29. r2 = random(700000);
  30. sprintf(sql, "SELECT COUNT(*) AS count FROM posts_jx3 WHERE tid = %d;",r2);
  31. lr_log_message("%s",sql);
  32.         mysql_query(db, sql);
  33.         results2 = mysql_store_result(db);
  34.         while((record = mysql_fetch_row(results2)))
  35. {
  36.         lr_log_message("count = %d", record[0]);
  37.         }
  38. mysql_free_result(results2);
  39. page = count/10;
  40. lr_log_message("page = %d", page);
  41. for(j=0;j< =page;j++)
  42. {
  43. sprintf(sql, "SELECT *  FROM posts_jx3 WHERE tid = %d LIMIT %d,10;",r2,j);
  44. mysql_query(db, sql);
  45. lr_log_message("%s", sql);
  46. if (j>0) {
  47.   results2 = mysql_store_result(db);
  48.                   while((record = mysql_fetch_row(results2)))
  49.           {
  50.                      lr_log_message("pid = %d", record[0]);
  51.                    }
  52.           mysql_free_result(results2);
  53. }
  54. }
  55. }
  56. else //新数据,大部分 80%
  57. {
  58.         r2 = random(273505);
  59. r2 = r2+700000;
  60. sprintf(sql, "SELECT COUNT(*) AS count FROM posts_jx3 WHERE tid = %d;",r2);
  61. lr_log_message("%s",sql);
  62.         mysql_query(db, sql);
  63.         results2 = mysql_store_result(db);
  64.         while((record = mysql_fetch_row(results2)))
  65. {
  66. lr_log_message("count = %d", record[0]);
  67.         }
  68. mysql_free_result(results2);
  69. page = count/10;
  70. lr_log_message("page = %d", page);
  71.  
  72. for(j=0;j< =page;j++)
  73. {
  74. sprintf(sql, "SELECT *  FROM posts_jx3 WHERE tid = %d LIMIT %d,10;",r2,j);
  75. lr_log_message("%s", sql);
  76. mysql_query(db, sql);
  77. if (j>0) {
  78.   results2 = mysql_store_result(db);
  79.                   while((record = mysql_fetch_row(results2)))
  80.           {
  81.                       lr_log_message("pid = %d", record[0]);
  82.                    }
  83.           mysql_free_result(results2);
  84. }
  85. }
  86. }
  87. mysql_free_result(results2);
  88. return 0;
  89. }
  90.  
  91.  
  92.  
  93. int my_mysql_insert()
  94. {
  95. int t;
  96.     char sql[500];
  97. MYSQL_RES *results3;
  98. sprintf(sql,"%s","INSERT INTO posts_jx3 ( fid, tid, first, author, authorid, subject, dateline, message, useip, invisible, anonymous, usesig, htmlon, bbcodeoff, smileyoff, parseurloff, attachment, rate, ratetimes, status) VALUES ( 12345, 215053, 0, 'fdsafsdfsd', 2265065, '', 1240535917, 'fdsfsdfdsfd', '118.239.49.229', 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, 0);");
  99. lr_log_message("%s", sql);
  100.     t = mysql_query(db, sql);
  101. if(t)
  102. {
  103. lr_log_message("%s", mysql_error(db));
  104. }
  105. else
  106. {
  107. lr_log_message("%s", "suc");
  108. }
  109. }
]]>
http://www.sunboyu.cn/2011/01/06/%e5%88%a9%e7%94%a8loadrunner%e5%81%9amysql%e5%8e%8b%e5%8a%9b%e6%b5%8b%e8%af%95.shtml/feed
一个备份mysql的脚本,很简单 http://www.sunboyu.cn/2009/07/29/%e4%b8%80%e4%b8%aa%e5%a4%87%e4%bb%bdmysql%e7%9a%84%e8%84%9a%e6%9c%ac%ef%bc%8c%e5%be%88%e7%ae%80%e5%8d%95.shtml http://www.sunboyu.cn/2009/07/29/%e4%b8%80%e4%b8%aa%e5%a4%87%e4%bb%bdmysql%e7%9a%84%e8%84%9a%e6%9c%ac%ef%bc%8c%e5%be%88%e7%ae%80%e5%8d%95.shtml#comments Wed, 29 Jul 2009 13:43:46 +0000 admin http://www.sunboyu.cn/?p=927 帮朋友维护服务器的时候,习惯性得检查各项服务和维护,偶然间发现了这个脚本,冒着被BS的风险分享给大家,希望大家捧个钱场,施舍给老衲几万块钱买套房。

  1. @echo off
  2. C:
  3. CD "C:\Program Files\WinRAR"
  4.  
  5. net stop Mysql
  6. winrar.exe a -ag"-[YYYY-MM-DD-HH-MM-SS]" -k -r -s -ibck -inul "D:\MYSQL备份生成的文件.rar" "E:\bak\data\*.*"
  7. net start Mysql
]]>
http://www.sunboyu.cn/2009/07/29/%e4%b8%80%e4%b8%aa%e5%a4%87%e4%bb%bdmysql%e7%9a%84%e8%84%9a%e6%9c%ac%ef%bc%8c%e5%be%88%e7%ae%80%e5%8d%95.shtml/feed
Python写的数据抽象层 http://www.sunboyu.cn/2009/03/30/python%e5%86%99%e7%9a%84%e6%95%b0%e6%8d%ae%e6%8a%bd%e8%b1%a1%e5%b1%82.shtml http://www.sunboyu.cn/2009/03/30/python%e5%86%99%e7%9a%84%e6%95%b0%e6%8d%ae%e6%8a%bd%e8%b1%a1%e5%b1%82.shtml#comments Mon, 30 Mar 2009 03:26:09 +0000 admin http://www.sunboyu.cn/?p=622 python本身没有对mysql的支持,得依赖附加的库 http://mysql-python.sourceforge.net 。很多框架采用了这个库,比如adodb,django等。不过我倾向于自己写这些东西,所以小研究了一下。 mysql-python 有两个对象 MySQLdb _mysql 这里是介绍http://mysql-python.sourceforge.net/MySQLdb.html,我使用的是 MySQLdb 对象

  1. #!/D:\python25\python.exe
  2. import MySQLdb
  3.  
  4. class Mysql(object):
  5.     handle = ''
  6.     query = ''
  7.     exectime = 0
  8.     effected = 0
  9.  
  10.     def __init__( self , hostname , username , password , database ):
  11.         db = MySQLdb.connect( host = hostname , user = username , passwd = password , db = database )
  12.         self.handle = db.cursor()
  13.         
  14.     def query( self , sql = '' ):
  15.         return self.handle.execute( sql )
  16.  
  17.     def fetch( self , sql = '' ):
  18.         self.handle.execute( sql )
  19.         rs = self.handle.fetchone()
  20.         count = 0
  21.         result = {}
  22.         for colnum in self.handle.description:
  23.             result[colnum[0]] = rs[count]
  24.             count += 1
  25.         return result
  26.     
  27.     def fetchAll( self , sql = '' ):
  28.         self.handle.execute( sql )
  29.         result = {}
  30.         bigcount = 0
  31.         for recordline in self.handle.fetchall():
  32.             littlecount = 0
  33.             result[bigcount] = {}
  34.             for colnum in self.handle.description:
  35.                 result[bigcount][colnum[0]] = recordline[littlecount]
  36.                 littlecount += 1
  37.             bigcount += 1
  38.         return result
  39.  
  40.     def insertID( self ):
  41.           self.handle.execute("SELECT LAST_INSERT_ID() AS lid")
  42.           rs = self.handle.fetchone()
  43.           return rs[0]
  44.  
  45.     def close( self ):
  46.           self.handle.close()
  47.           pass
  48. #DEMO
  49. db = Mysql('localhost','root','123456','frame')
  50. db.fetchAll('select * from user')
  51. #rs = db.fetchAll('select * from user')
  52. #sql = "INSERT INTO tags (module,fid,name,note,`order`) VALUE ('test',1,'fd','ds',1)"
  53. #db.query(sql)
  54. #print db.insertID()
]]>
http://www.sunboyu.cn/2009/03/30/python%e5%86%99%e7%9a%84%e6%95%b0%e6%8d%ae%e6%8a%bd%e8%b1%a1%e5%b1%82.shtml/feed
mysql索引优化 http://www.sunboyu.cn/2009/02/15/mysql%e7%b4%a2%e5%bc%95%e4%bc%98%e5%8c%96.shtml http://www.sunboyu.cn/2009/02/15/mysql%e7%b4%a2%e5%bc%95%e4%bc%98%e5%8c%96.shtml#comments Sun, 15 Feb 2009 06:01:09 +0000 admin http://www.sunboyu.cn/?p=568 做复杂的数据报表经常要很多sql语句连续执行,不是超时就是把mysql跑挂。不过现在硬件廉价,这些软件完美得兼容了多核多线程,虽然一个mysql进程负载高,但只占用一个内核,其他的查询依然可以使用其他的内核进行运算,服务器不会整体挂掉。

mysql优化,主要是索引,大量消耗资源的查询一定要做相关索引优化,具体优化思想我是阅读的这本书-http://www.douban.com/subject/3039216/ 里边mysql优化部分讲得非常简洁明了。而对于cpu的优化,就是尽力把整体时间拉开,cpu会比较平稳。具体做法是用sleep把sql语句分隔,这样用时间换取了稳定。当然,有些报表数据一旦作出就不会再变,这时最好把这些数据文本缓存,以后查询只读取文本即可。

]]>
http://www.sunboyu.cn/2009/02/15/mysql%e7%b4%a2%e5%bc%95%e4%bc%98%e5%8c%96.shtml/feed
sunboyu-amp-fastcgi-suexec-v21-alpha 发布 http://www.sunboyu.cn/2008/12/15/sunboyu-amp-fastcgi-suexec-v21-alpha-%e5%8f%91%e5%b8%83.shtml http://www.sunboyu.cn/2008/12/15/sunboyu-amp-fastcgi-suexec-v21-alpha-%e5%8f%91%e5%b8%83.shtml#comments Mon, 15 Dec 2008 13:58:14 +0000 admin http://www.sunboyu.cn/?p=428 Linux下APACHE MYSQL PHP FCgid Suexec 自动安装脚本V2.1
1、增加了PHP –enable-bcmath 参数,支持高精度函数库
2、增加了ncurses MYSQL的一个依赖库
3、增加了apache –enable-so 参数

sunboyu-amp-fastcgi-suexec-v21-alpha

此脚本在Centos4.7ServerCD 最小安装,root账户下执行完全正常。

]]>
http://www.sunboyu.cn/2008/12/15/sunboyu-amp-fastcgi-suexec-v21-alpha-%e5%8f%91%e5%b8%83.shtml/feed
Windows下安装Apache,Mysql,PHP过程详解 http://www.sunboyu.cn/2008/12/04/windows%e4%b8%8b%e5%ae%89%e8%a3%85apache%ef%bc%8cmysql%ef%bc%8cphp%e8%bf%87%e7%a8%8b%e8%af%a6%e8%a7%a3.shtml http://www.sunboyu.cn/2008/12/04/windows%e4%b8%8b%e5%ae%89%e8%a3%85apache%ef%bc%8cmysql%ef%bc%8cphp%e8%bf%87%e7%a8%8b%e8%af%a6%e8%a7%a3.shtml#comments Thu, 04 Dec 2008 01:40:14 +0000 admin http://www.sunboyu.cn/?p=409 原则:使用官方程序,完全自己配置,不使用其他辅助工具套件等。

准备:

apache2.2.*   http://httpd.apache.org/download.cgi   如果有stable版本,最好用stable版,其实最新版作为调试也不错

PHP5.2.*  http://www.php.net/downloads.php  目前是5.2.6

mysql5.1  http://dev.mysql.com/downloads/mysql/5.1.html  下载windows安装版本

1、安装Apache,安装路径随意,默认即可,手工管理更好,建议放到 d:\Apache 放D盘是为了以后重装的话,所有的配置文件都还在(备份不仅要备份数据,还要备份不起眼的配置文件)

2、安装Mysql,同上,安装到 D:\Mysql  理由同上

3、解压PHP5.2.×至目录 D:\PHP5 理由还是同上

4、配置环境变量:在桌面上找到“我的电脑”,右键点击“我的电脑”,选择“属性”里的“高级”标签,点击“环境变量”,在“系统变量”里找到“Path”,点击“编辑”按钮,在“变量值”后面加上“;D:\PHP5\;D:\PHP5\ext”,然后点“确定”退出。环境变量配置完成。(windows下Path环境变量是做什么用,google一下先,这样设置后,系统会自动搜索PHP目录里的可执行文件和加载类库)

5、进入PHP5目录下,找到php.ini-dist文件,将其复制到C盘的WINDOWS目录下,并将其文件名修改为“php.ini”。(php会默认从这个路径找php.ini这个文件,当然也可以手工指定这个目录,修改apache的配置文件即可)

6、再次进入PHP5目录下,将以下文件复制到C盘的WINDOWS目录下的System32里:(原因,我也不太清楚,但貌似可以设置一个环境变量指向这个路径就ok,那个方法一直没找到,也没理解)
fdftk.dll
gds32.dll
libeay32.dll
libmcrypt.dll
libmhash.dll
libmysql.dll
msql.dll
news.txt
ntwdblib.dll

7、打开Apache的主目录,进入conf文件夹,找到“httpd.conf”文件,为操作方便起见,建议使用Dreamweaver打开它。打开后在第126行左右找到 LoadModule vhost_alias_module modules/mod_vhost_alias.so,在后面添加以下语句:
LoadModule php5_module “D:/PHP5/php5apache2_2_filter.dll
“AddType application/x-httpd-php .php
添加完成后保存文件。

8、在apache主目录下htdocs下创建index.php文件,内容为<?php phpinfo(); ?>保存。

9、在浏览器的地址栏里输入http://127.0.0.1/index.php。即可打开显示PHP信息的页面。配置成功。

]]>
http://www.sunboyu.cn/2008/12/04/windows%e4%b8%8b%e5%ae%89%e8%a3%85apache%ef%bc%8cmysql%ef%bc%8cphp%e8%bf%87%e7%a8%8b%e8%af%a6%e8%a7%a3.shtml/feed
MYSQL5新特性,分区表 http://www.sunboyu.cn/2008/11/15/mysql5%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%8c%e5%88%86%e5%8c%ba%e8%a1%a8.shtml http://www.sunboyu.cn/2008/11/15/mysql5%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%8c%e5%88%86%e5%8c%ba%e8%a1%a8.shtml#comments Sat, 15 Nov 2008 09:57:03 +0000 admin http://www.sunboyu.cn/?p=385 CU上看了一个介绍mysql5分区表的帖子,很感兴趣,如果有了分区的应用,那么设计数据库结构可以更加紧凑,而在应用上更加灵活,减少了一些不必要的视图,而在速度上也很好的提升。
分区的好处是,在物理上根据规则对表进行分离。
水平分区其实是B树索引物理上又增加了一级,当然要提高检索速度了,因为又多了一个手工索引。
垂直分区,在一些应用上会更加方便,比如discuz程序,帖子标题跟正文都是分离的,目的是降低单表容量,而有了垂直分区,可以在物理上对字段进行分离,而访问的时候又是类似视图的访问,无比爽也!!
目前还没测试分区到底有多少性能潜力可开发,回头用大的数据查询测试一下。
相关资料:http://dev.mysql.com/doc/refman/5.1/zh/partitioning.html

]]>
http://www.sunboyu.cn/2008/11/15/mysql5%e6%96%b0%e7%89%b9%e6%80%a7%ef%bc%8c%e5%88%86%e5%8c%ba%e8%a1%a8.shtml/feed
Mysql数据库抽象层操作类 http://www.sunboyu.cn/2008/09/08/mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%8a%bd%e8%b1%a1%e5%b1%82%e6%93%8d%e4%bd%9c%e7%b1%bb.shtml http://www.sunboyu.cn/2008/09/08/mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%8a%bd%e8%b1%a1%e5%b1%82%e6%93%8d%e4%bd%9c%e7%b1%bb.shtml#comments Mon, 08 Sep 2008 06:26:23 +0000 admin http://www.sunboyu.cn/?p=308 DB.InterFace.php

  1. <?php
  2. /*  DB.InterFace.php
  3.  *  DB
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 28  sunboyu@gmail.com
  9.  *  Demo
  10.  */
  11. interface DateBaseConnect
  12. {
  13.     #数据库连接
  14.     public function Connect( $host , $user , $pass , $datebase );
  15. #使用数据库
  16. public function selectDateBase( $datebase );
  17. #执行一个查询
  18. public function Query( $sql );
  19. #取得一行
  20. public function fetchRow( $sql );
  21. #取得所有
  22. public function fetchAll( $sql );
  23. #取得影响行数
  24. public function affectedRow();
  25. #取得结果行数
  26. public function recordCount();
  27. #取得上次插入ID
  28. public function insertID();
  29. #释放资源
  30. public function close();
  31. }
  32. ?>


DB.Mysql.Class.php

  1. <?php
  2. /*  DB.Mysql.Class.php
  3.  *  Mysql
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 28  sunboyu@gmail.com
  9.  *  Demo
  10.  */
  11. require_once(ROOT."/Include/Class/DB.InterFace.php");
  12. class Mysql implements DateBaseConnect
  13. {
  14. #连接标识
  15. public $handle = false;
  16. #结果标识
  17. public $query;
  18. #查询次数
  19. public $exetime;
  20. #数据库连接
  21.     public function Connect( $host , $user , $pass , $datebase )
  22. {
  23. $this->handle = @mysql_connect( $host , $user , $pass , false ) or die("Can't connetc to the DateBse.".mysql_error());
  24. $this->selectDateBase( $datebase );
  25. $this->exetime = 0;
  26. }
  27. #使用数据库
  28. public function selectDateBase( $datebase )
  29. {
  30. @mysql_select_db( $datebase , $this->handle ) or die("Can't select the DateBase".mysql_error());
  31. }
  32. #执行一个查询
  33. public function Query( $sql )
  34. {
  35. $this->query = mysql_query( $sql , $this->handle ) or die("query error".mysql_error());
  36. $this->exetime++;
  37. return true;
  38. }
  39. #取得一行
  40. public function fetchRow( $sql )
  41. {
  42. $this->Query( $sql );
  43. while( $row = mysql_fetch_array( $this->query, MYSQL_ASSOC ) )
  44. {
  45. return $row;
  46.     }
  47. return false;
  48. }
  49. #取得所有
  50. public function fetchAll( $sql )
  51. {
  52. $this->Query( $sql );
  53. $rows = false;
  54. while( $rs = mysql_fetch_array( $this->query, MYSQL_ASSOC ) )
  55. {
  56. $rows[] = $rs;
  57. }
  58. return $rows;
  59. }
  60. #取得影响行数
  61. public function affectedRow()
  62. {
  63. return mysql_affected_rows( $this->query );
  64. }
  65. #取得结果行数
  66. public function recordCount()
  67. {
  68. return mysql_num_rows( $this->query );
  69. }
  70. #取得上次插入ID
  71. public function insertID()
  72. {
  73. return (mysql_insert_id()>0) ? mysql_insert_id() : false;
  74. }
  75. #释放资源
  76. public function close()
  77. {
  78. @mysql_close( $this->handle );
  79. }
  80. #析构函数
  81. /*
  82. function __destruct()
  83. {
  84. $this->close();
  85. }
  86. */
  87. }
  88. ?>

DB.Mysql.Fact.Class.php

  1. <?php
  2. /*  DB.Mysql.Fact.Class.php
  3.  *  Mysql
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 28  sunboyu@gmail.com
  9.  *  Demo
  10.  */
  11. require_once(ROOT."/Include/Class/DB.Mysql.Class.php");
  12. class DB extends Mysql
  13. {
  14.     #插入操作
  15. /*
  16. $array = array(
  17.     'name' = "sunboyu",
  18. 'pass' = "123456"
  19. );
  20. */
  21. function __insert( $array , $table )
  22. {
  23.     $sql = "INSERT INTO {$table} (";
  24.     if(!is_array($array))
  25. {
  26.     die('the array is not a array!');
  27. }
  28. $keys = array_keys( $array );
  29. $sql .= implode( ',' , $keys );
  30. $sql .= ") VALUES (";
  31. foreach( $array as $key=>$value )
  32. {
  33.     if(is_int( $array[$key] ))
  34. {
  35.     $sql .= $array[$key];
  36. }
  37. else if(is_string( $array[$key] ))
  38. {
  39.     $sql .= "'{$array[$key]}'";
  40. }
  41. $sql .= ",";
  42. }
  43. $sql = substr_replace( $sql , "" , -1 );
  44. $sql .= ")";
  45. return $this->Query( $sql );
  46. }
  47. }
  48. ?>
]]>
http://www.sunboyu.cn/2008/09/08/mysql%e6%95%b0%e6%8d%ae%e5%ba%93%e6%8a%bd%e8%b1%a1%e5%b1%82%e6%93%8d%e4%bd%9c%e7%b1%bb.shtml/feed
Mysql视图应用 http://www.sunboyu.cn/2008/08/28/mysql%e8%a7%86%e5%9b%be%e5%ba%94%e7%94%a8.shtml http://www.sunboyu.cn/2008/08/28/mysql%e8%a7%86%e5%9b%be%e5%ba%94%e7%94%a8.shtml#comments Thu, 28 Aug 2008 12:55:26 +0000 admin http://www.sunboyu.cn/?p=290 mysql视图创建方法,以我的OpenOA为例,创建user表left jion user_info表的视图

CREATE VIEW v_user AS SELECT * FROM user LEFT JOIN user_info ON (user.id = user_info.user_id)

然后查看

mysql>use oa

mysql>show tables

结果显示,v_user是库oa中的一个表。因此我们使用的时候,可以直接使用语句 SELECT * FROM v_user

而这句也就等于 SELECT * FROM user LEFT JOIN user_info ON (user.id = user_info.user_id)

而实习在系统中,v_user 只有这么一个文件v_user.frm  也就是只有结构,没有数据和索引.打开后,可以看到详细的存储的内容

TYPE=VIEW
query=select `oa`.`user`.`id` AS `id`,`oa`.`user`.`username` AS `username`,`oa`.`user`.`nickname` AS `nickname`,`oa`.`user`.`password` AS `password`,`oa`.`user`.`lastlogintime` AS `lastlogintime`,`oa`.`user`.`lastloginip` AS `lastloginip`,`oa`.`user`.`loginrand` AS `loginrand`,`oa`.`user_info`.`user_id` AS `user_id`,`oa`.`user_info`.`user_realname` AS `user_realname`,`oa`.`user_info`.`user_sex` AS `user_sex`,`oa`.`user_info`.`user_age` AS `user_age`,`oa`.`user_info`.`user_birthplace` AS `user_birthplace`,`oa`.`user_info`.`user_homeaddress` AS `user_homeaddress`,`oa`.`user_info`.`user_idcard` AS `user_idcard`,`oa`.`user_info`.`user_graduateschool` AS `user_graduateschool`,`oa`.`user_info`.`user_educational` AS `user_educational`,`oa`.`user_info`.`user_graduatetime` AS `user_graduatetime`,`oa`.`user_info`.`user_homephone` AS `user_homephone`,`oa`.`user_info`.`user_cellphone` AS `user_cellphone`,`oa`.`user_info`.`user_workphone` AS `user_workphone`,`oa`.`user_info`.`user_fax` AS `user_fax`,`oa`.`user_info`.`user_email` AS `user_email`,`oa`.`user_info`.`user_oicq` AS `user_oicq`,`oa`.`user_info`.`user_msn` AS `user_msn` from (`oa`.`user` left join `oa`.`user_info` on((`oa`.`user`.`id` = `oa`.`user_info`.`user_id`)))
md5=19f7a28463ad7447c3b4cc5428888fa6
updatable=0
algorithm=0
definer_user=root
definer_host=localhost
suid=1
with_check_option=0
revision=1
timestamp=2008-08-28 11:58:17
create-version=1
source=SELECT * FROM user LEFT JOIN user_info ON ( user.id = user_info.user_id )

都是啥意思,没有深究,只是能根据字面猜出来,如果只是用,到此位置即可。

]]>
http://www.sunboyu.cn/2008/08/28/mysql%e8%a7%86%e5%9b%be%e5%ba%94%e7%94%a8.shtml/feed
使用mysql保存session,并建立在线用户列表 http://www.sunboyu.cn/2008/08/15/%e4%bd%bf%e7%94%a8mysql%e4%bf%9d%e5%ad%98session%ef%bc%8c%e5%b9%b6%e5%bb%ba%e7%ab%8b%e5%9c%a8%e7%ba%bf%e7%94%a8%e6%88%b7%e5%88%97%e8%a1%a8.shtml http://www.sunboyu.cn/2008/08/15/%e4%bd%bf%e7%94%a8mysql%e4%bf%9d%e5%ad%98session%ef%bc%8c%e5%b9%b6%e5%bb%ba%e7%ab%8b%e5%9c%a8%e7%ba%bf%e7%94%a8%e6%88%b7%e5%88%97%e8%a1%a8.shtml#comments Fri, 15 Aug 2008 15:02:21 +0000 admin http://www.sunboyu.cn/?p=280 写OA,使用mysql存储session,这样,是为了获得在线用户的列表,为做一个web im做准备。

首先创建表,注,这里使用了adodb中数据字典的描述方法:

  1. $Session_Fields = "
  2. session_id VARCHAR(100) NOTNULL,
  3. session_value X DEFAULT '',
  4. session_expires I(10) DEFAULT NULL,
  5. userid I(5) DEFAULT NULL
  6. ";
  7. $Session_Tables = array('mysql' => "ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci COMMENT = 'session表'");
  8. $dict = NewDataDictionary(GetDB());
  9. $sqlarray = $dict->CreateTableSQL($_CFG['table']['session'], $Session_Fields, $Session_Tables);
  10. $dict->ExecuteSQLArray($sqlarray);

然后session类:

  1. <?php
  2. /*  Session.Class.php
  3.  *  Session Manager
  4.  *  @link        http://www.sunboyu.cn
  5.  *  @package     OA
  6.  *  @version     V1.0
  7.  *
  8.  *  2008 08 14  sunboyu@gmail.com
  9.  */
  10. class Session
  11. {
  12. var $lifetime;
  13. var $db = null;
  14. function __construct()
  15. {
  16. #return adodb lite connetction
  17. $this->db = GetDB();
  18. }
  19. #open
  20. function open( $savepath , $session_name )
  21. {
  22. $this->lifetime =  get_cfg_var("session.gc_maxlifetime");
  23. return true;
  24. }
  25. #close
  26. function close()
  27. {
  28. return true;
  29. }
  30. #read
  31. function read( $session_id )
  32. {
  33. global $_CFG;
  34. $sql = sprintf("SELECT * FROM %s WHERE session_id = %s",$_CFG['table']['session'],GetSqlString( $session_id ));
  35. $rs = $this->db->Execute( $sql );
  36. if($rs->RecordCount()>0)
  37. {
  38. $result = $rs->fields;
  39. return $result['session_value'];
  40. }
  41. else
  42. {
  43. return null;
  44. }
  45. }
  46. #write
  47. function write( $session_id , $session_value )
  48. {
  49. global $_CFG;
  50. $sql = sprintf("SELECT session_id FROM %s WHERE session_id = %s",$_CFG['table']['session'],GetSqlString( $session_id ));
  51. $rs = $this->db->Execute( $sql );
  52. if($rs->RecordCount()==0)
  53. {
  54. $newsql = sprintf("INSERT INTO %s SET session_id = %s , session_value = %s , session_expires = %d",
  55. $_CFG['table']['session'],
  56. GetSqlString( $session_id ),
  57. GetSqlString( $session_value ),
  58. GetSqlString( $this->lifetime+time() , "int" ));
  59. }
  60. else
  61. {
  62. $newsql = sprintf("UPDATE %s SET session_value = %s , session_expires = %d WHERE session_id = %s",
  63. $_CFG['table']['session'],
  64. GetSqlString( $session_value ),
  65. GetSqlString( $this->lifetime+time() , "int" ),
  66. GetSqlString( $session_id ));
  67. }
  68. return $this->db->Execute( $newsql );
  69. }
  70. #destroy
  71. function destroy( $session_id )
  72. {
  73. global $_CFG;
  74. $delsql = sprintf("DELETE FROM %s WHERE session_id = %s",$_CFG['table']['session'],GetSqlString( $session_id ));
  75. return $this->db->Execute( $delsql );
  76. }
  77. #gc
  78. function gc()
  79. {
  80. global $_CFG;
  81. $gcsql = sprintf("DELETE FROM %s WHERE session_expires < %d",$_CFG['table']['session'],time());
  82. return $this->db->Execute( $gcsql );
  83. }
  84. }
  85. ?>

session机制,之前已经介绍,实现代码如下

  1. $session = new Session();
  2. session_set_save_handler(array(&$session,"open"),
  3. array(&$session,"close"),
  4. array(&$session,"read"),
  5. array(&$session,"write"),
  6. array(&$session,"destroy"),
  7. array(&$session,"gc"));
  8. session_start();

把session与用户id对应,使用以下语句即可

  1. sprintf("UPDATE %s SET userid = %d WHERE session_id = %s",$_CFG['table']['session'],GetSqlString($rs['id'],'int'),GetSqlString(session_id(),'text'))
]]>
http://www.sunboyu.cn/2008/08/15/%e4%bd%bf%e7%94%a8mysql%e4%bf%9d%e5%ad%98session%ef%bc%8c%e5%b9%b6%e5%bb%ba%e7%ab%8b%e5%9c%a8%e7%ba%bf%e7%94%a8%e6%88%b7%e5%88%97%e8%a1%a8.shtml/feed
使用Mysql来存储Session http://www.sunboyu.cn/2008/07/31/%e4%bd%bf%e7%94%a8mysql%e6%9d%a5%e5%ad%98%e5%82%a8session.shtml http://www.sunboyu.cn/2008/07/31/%e4%bd%bf%e7%94%a8mysql%e6%9d%a5%e5%ad%98%e5%82%a8session.shtml#comments Thu, 31 Jul 2008 14:39:29 +0000 admin http://www.sunboyu.cn/?p=236 接上篇,我们已经知道session的具体存储机制,我们来尝试修改一下这个机制,让数据存储在mysql数据库中。

mysql有三部分的内容,session session_data session_expires分别为session的id session的内容,session的过期时间。

创建这样一个数据库

CREATE TABLE IF NOT EXISTS `sessions` (
`session` varchar(255) character set utf8 collate utf8_bin NOT NULL,
`session_expires` int(10) unsigned NOT NULL default ‘0′,
`session_data` mediumtext collate utf8_unicode_ci,
KEY `session` (`session`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

相对于文件方式的session存储,这两个函数是不用动的
function open($save_path, $session_name)
{
global $sess_save_path;

$sess_save_path = $save_path;
return(true);
}

function close()
{
return(true);
}
而需要修改的是读,写,删,过期操作的函数

读的操作,很简单,只是从数据库中,根据sessionid,读出date字段中的内容
function read($sessID) {
global $php_errormsg;
// fetch session-data
$query = ”
SELECT session_data FROM sessions
WHERE session = ‘$sessID’
AND session_expires >
“.time();
$result = $this->mdb2->query($query);
// return data or an empty string at failure
if (MDB2::isError($result)) {
$php_errormsg .= $result->getMessage();
$php_errormsg .= $result->getDebugInfo ();
return false;
}
list($value)=@$result->fetchrow();
return $value;
}
同理,写的操作就是update数据,destory的操作为删除session的记录,另外有个gc的操作是删除过期的session。
具体的代码没有去实现,但在PHP手册上都有。同时手册还介绍了memcache储存的方式,效率应该会不错的。

这是本月最后一篇日志,也算为下月找个题。

]]>
http://www.sunboyu.cn/2008/07/31/%e4%bd%bf%e7%94%a8mysql%e6%9d%a5%e5%ad%98%e5%82%a8session.shtml/feed
MYSQL无法编译,可能存在的问题 http://www.sunboyu.cn/2008/07/19/mysql%e6%97%a0%e6%b3%95%e7%bc%96%e8%af%91%ef%bc%8c%e5%8f%af%e8%83%bd%e5%ad%98%e5%9c%a8%e7%9a%84%e9%97%ae%e9%a2%98.shtml http://www.sunboyu.cn/2008/07/19/mysql%e6%97%a0%e6%b3%95%e7%bc%96%e8%af%91%ef%bc%8c%e5%8f%af%e8%83%bd%e5%ad%98%e5%9c%a8%e7%9a%84%e9%97%ae%e9%a2%98.shtml#comments Sat, 19 Jul 2008 07:32:07 +0000 admin http://www.sunboyu.cn/?p=203 =============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
mysql-devel             i386       5.0.45-7.el5     base              2.4 M
Installing for dependencies:
e2fsprogs-devel         i386       1.39-15.el5      base              568 k
keyutils-libs           i386       1.2-1.el5        base               18 k
keyutils-libs-devel     i386       1.2-1.el5        base               27 k
krb5-devel              i386       1.6.1-25.el5     base              1.9 M
libselinux-devel        i386       1.33.4-5.el5     base              131 k
libsepol-devel          i386       1.15.2-1.el5     base              189 k
mysql                   i386       5.0.45-7.el5     base              4.1 M
openssl-devel           i386       0.9.8b-10.el5    base              1.8 M
perl-DBI                i386       1.52-1.fc6       base              605 k
zlib-devel              i386       1.2.3-3          base              101 k
Updating for dependencies:
e2fsprogs               i386       1.39-15.el5      base              964 k
e2fsprogs-libs          i386       1.39-15.el5      base              116 k
krb5-libs               i386       1.6.1-25.el5     base              656 k
krb5-workstation        i386       1.6.1-25.el5     base              872 k
libselinux              i386       1.33.4-5.el5     base               94 k
libselinux-python       i386       1.33.4-5.el5     base               58 k
openssl                 i686       0.9.8b-10.el5    base              1.4 M

Transaction Summary

还有就是mysql,client的问题
checking whether to include mime_magic support… yes
checking for MING support… no
checking for mSQL support… yes
checking mSQL version… 1.0
checking for MSSQL support via FreeTDS… no
checking for MySQL support… yes
checking for specified location of the MySQL UNIX socket… /tmp/mysql.sock
checking for MySQL UNIX socket location… /tmp/mysql.sock
checking for mysql_close in -lmysqlclient… no
checking for mysql_error in -lmysqlclient… no
configure: error: mysql configure failed. Please check config.log for more information.
make: *** No targets specified and no makefile found.  Stop.

rpm -Uvh glibc-kernheaders-2.4-9.1.98.EL.x86_64.rpm
rpm -Uvh glibc-headers-2.3.4-2.19.x86_64.rpm
rpm -Uvh glibc-devel-2.3.4-2.19.x86_64.rpm
rpm -Uvh cpp-3.4.5-2.x86_64.rpm
rpm -Uvh gcc-3.4.5-2.x86_64.rpm
rpm -Uvh libstdc++-devel-3.4.5-2.x86_64.rpm
rpm -Uvh gcc-c++-3.4.5-2.x86_64.rpm

]]>
http://www.sunboyu.cn/2008/07/19/mysql%e6%97%a0%e6%b3%95%e7%bc%96%e8%af%91%ef%bc%8c%e5%8f%af%e8%83%bd%e5%ad%98%e5%9c%a8%e7%9a%84%e9%97%ae%e9%a2%98.shtml/feed
Mysql Max官方停止支持了 http://www.sunboyu.cn/2008/07/19/mysql-max%e5%ae%98%e6%96%b9%e5%81%9c%e6%ad%a2%e6%94%af%e6%8c%81%e4%ba%86.shtml http://www.sunboyu.cn/2008/07/19/mysql-max%e5%ae%98%e6%96%b9%e5%81%9c%e6%ad%a2%e6%94%af%e6%8c%81%e4%ba%86.shtml#comments Sat, 19 Jul 2008 06:16:16 +0000 admin http://www.sunboyu.cn/?p=202 最近一直在研究LAMP的构建,在编译php的时候,有个错误一直过不去,configure: error: mysql configure failed. Please check config.log for more information.后仔细排查后,根据网友提示,需要安装mysql-max版本,可官方已经不提供了。网友也普遍反映官网上没了。看来mysql被sun收购后,真的快要步入商业化了。

自从mysql官方不支持集群后,我就对mysql有点恐怖了,这么依赖,基础应用也快要不行了。

]]>
http://www.sunboyu.cn/2008/07/19/mysql-max%e5%ae%98%e6%96%b9%e5%81%9c%e6%ad%a2%e6%94%af%e6%8c%81%e4%ba%86.shtml/feed
打造全能优化的Linux+Apache+PHP+Mysql服务器(2) http://www.sunboyu.cn/2008/07/15/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%882%ef%bc%89.shtml http://www.sunboyu.cn/2008/07/15/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%882%ef%bc%89.shtml#comments Tue, 15 Jul 2008 03:33:13 +0000 admin http://www.sunboyu.cn/?p=197 MYsql的安装

mysql 编译参数
./configure –enable-thread-safe-client –enable-local-infile –enable-largefile –with-charset=utf8  –with-uca –with-gnu-ld –with-pic –with-mysqld-libs –with-comment –with-query-cache –with-bench –with-big-tables –with-innodb –with-mysqld-use=mysql

/usr/local/bin/mysql_install_db

/usr/local/bin/mysqld_safe  –user mysql

如果安装时候有错误提示,也许是缺少这个组件  http://www.sunboyu.cn/sourse/termcap-1.3.1.tar.gz

]]>
http://www.sunboyu.cn/2008/07/15/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%882%ef%bc%89.shtml/feed
打造全能优化的Linux+Apache+PHP+Mysql服务器(1) http://www.sunboyu.cn/2008/07/13/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%881%ef%bc%89.shtml http://www.sunboyu.cn/2008/07/13/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%881%ef%bc%89.shtml#comments Sun, 13 Jul 2008 13:05:51 +0000 admin http://www.sunboyu.cn/?p=196 fastcgi   http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
apache2   http://apache.mirror.phpchina.com/httpd/httpd-2.2.9.tar.gz
mysql5    http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51b.tar.gz/from/http://mysql.mirrors.arminco.com/
php5      http://cn2.php.net/distributions/php-5.2.6.tar.gz
libxml2
gd-jpeg   ftp://192.48.96.9/graphics/jpeg/jpegsrc.v6b.tar.gz
freetype  http://voxel.dl.sourceforge.net/sourceforge/freetype/freetype-2.3.7.tar.gz
libpng    http://voxel.dl.sourceforge.net/sourceforge/libpng/libpng-1.2.29.tar.gz
zend      http://www.zend.com/download/55

memcached  http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz
memcache   http://pecl.php.net/get/memcache-3.0.1.tgz
libevent   http://www.monkey.org/~provos/libevent-1.2a.tar.gz

目前想到的功能大概有这些,想到再加。

目前正在研究每一个组件的性能和参数。

]]>
http://www.sunboyu.cn/2008/07/13/%e6%89%93%e9%80%a0%e5%85%a8%e8%83%bd%e4%bc%98%e5%8c%96%e7%9a%84linuxapachephpmysql%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%881%ef%bc%89.shtml/feed
程序调式N多招 http://www.sunboyu.cn/2008/07/08/%e7%a8%8b%e5%ba%8f%e8%b0%83%e5%bc%8fn%e5%a4%9a%e6%8b%9b.shtml http://www.sunboyu.cn/2008/07/08/%e7%a8%8b%e5%ba%8f%e8%b0%83%e5%bc%8fn%e5%a4%9a%e6%8b%9b.shtml#comments Tue, 08 Jul 2008 12:00:13 +0000 admin http://www.sunboyu.cn/?p=184 最近在群里扯淡,好多小鸟提的问题其实很简单,程序本身的报错机制就能告诉你错误。现在列出所有能给你提示的方法.

  1. 打开PHP的报错。在php.ini(win下)中,寻找  error_reporting   ,设置 error_reporting  =  E_ALL & ~E_NOTICE,好像默认就是这个。
  2. 如果还是找不到,那么在你程序的头上加上:error_reporting(2047),这样错误也都会出来。

这两条是程序有硬伤的时候,直接报出来。如果逻辑上的错误,咋调呢?我的方法比较奔,但的确有效。

  1. 输入echo “aaa”;break; 这样,可以判断出程序是哪里出问题而中断了。
  2. print_r($var);这样去跟踪你认为出错的数据,用肉眼监视+大脑计算,去对比程序的计算,只要涉及变量值可能改变的地方,都得去对比。

这是程序差错的方法。mysql就更简单了,把你认为有错误的sql语句echo出来,放到phpmyadmin里去执行,看那个报错就行了。

最后一点:下载个星际译王,当然是指英文不太利索的。

]]>
http://www.sunboyu.cn/2008/07/08/%e7%a8%8b%e5%ba%8f%e8%b0%83%e5%bc%8fn%e5%a4%9a%e6%8b%9b.shtml/feed
开始学习C http://www.sunboyu.cn/2008/07/02/%e5%bc%80%e5%a7%8b%e5%ad%a6%e4%b9%a0c.shtml http://www.sunboyu.cn/2008/07/02/%e5%bc%80%e5%a7%8b%e5%ad%a6%e4%b9%a0c.shtml#comments Wed, 02 Jul 2008 00:52:03 +0000 admin http://www.sunboyu.cn/?p=168 昨天正式开始复习C语言,在大数据量的分析中,C,JAVA这些语言还是占有很大优势。以后用C的地方可能很多,平时复习一点为好。

http://www.bloodshed.net/     这个开发工具不错,一个轻量级的。

昨天第一课,用C连接mysql,失败了,继续。

]]>
http://www.sunboyu.cn/2008/07/02/%e5%bc%80%e5%a7%8b%e5%ad%a6%e4%b9%a0c.shtml/feed
mysql连接机制笔记 http://www.sunboyu.cn/2008/07/01/mysql%e8%bf%9e%e6%8e%a5%e6%9c%ba%e5%88%b6%e7%ac%94%e8%ae%b0.shtml http://www.sunboyu.cn/2008/07/01/mysql%e8%bf%9e%e6%8e%a5%e6%9c%ba%e5%88%b6%e7%ac%94%e8%ae%b0.shtml#comments Tue, 01 Jul 2008 02:20:04 +0000 admin http://www.sunboyu.cn/?p=167 php连接mysql是通过socket进行连接。mysql没有连接池,很郁闷的事情。

连接分 pconnect connect,connect是每次查询都新建一个连接。pconnect是在同一页面中,所有查询都使用一个连接。

]]>
http://www.sunboyu.cn/2008/07/01/mysql%e8%bf%9e%e6%8e%a5%e6%9c%ba%e5%88%b6%e7%ac%94%e8%ae%b0.shtml/feed
基于PHP-CLI的数据库备份管理软件今日奠基 http://www.sunboyu.cn/2008/06/20/%e5%9f%ba%e4%ba%8ephp-cli%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e7%ae%a1%e7%90%86%e8%bd%af%e4%bb%b6%e4%bb%8a%e6%97%a5%e5%a5%a0%e5%9f%ba.shtml http://www.sunboyu.cn/2008/06/20/%e5%9f%ba%e4%ba%8ephp-cli%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e7%ae%a1%e7%90%86%e8%bd%af%e4%bb%b6%e4%bb%8a%e6%97%a5%e5%a5%a0%e5%9f%ba.shtml#comments Fri, 20 Jun 2008 15:37:57 +0000 admin http://www.sunboyu.cn/?p=128 确定了基本的功能

  • 创建任务mysql数据库备份任务
  • 管理cron任务跟备份任务的结合
  • 任务管理

基本能满足一个网管备份mysql的日常操作。

由于是第一个版本,没做太多的功能,实现再说。

这个东东也是展示下PHP功能的强大。PHP代替Perl也不是不可能的。

]]>
http://www.sunboyu.cn/2008/06/20/%e5%9f%ba%e4%ba%8ephp-cli%e7%9a%84%e6%95%b0%e6%8d%ae%e5%ba%93%e5%a4%87%e4%bb%bd%e7%ae%a1%e7%90%86%e8%bd%af%e4%bb%b6%e4%bb%8a%e6%97%a5%e5%a5%a0%e5%9f%ba.shtml/feed
PHP+MYSQL循环插入1W条记录测试 http://www.sunboyu.cn/2008/06/16/php%ef%bc%8bmysql%e5%be%aa%e7%8e%af%e6%8f%92%e5%85%a51w%e6%9d%a1%e8%ae%b0%e5%bd%95%e6%b5%8b%e8%af%95.shtml http://www.sunboyu.cn/2008/06/16/php%ef%bc%8bmysql%e5%be%aa%e7%8e%af%e6%8f%92%e5%85%a51w%e6%9d%a1%e8%ae%b0%e5%bd%95%e6%b5%8b%e8%af%95.shtml#comments Mon, 16 Jun 2008 14:55:02 +0000 admin http://www.sunboyu.cn/?p=122 表test,字段 id,content
当id没有设置主键的时候,运行时间为 37.186923027
当id设置成主键的时候,运行时间为 44.7759540081
结论……该睡觉了
有点闲着慌

]]>
http://www.sunboyu.cn/2008/06/16/php%ef%bc%8bmysql%e5%be%aa%e7%8e%af%e6%8f%92%e5%85%a51w%e6%9d%a1%e8%ae%b0%e5%bd%95%e6%b5%8b%e8%af%95.shtml/feed
centos5安装指南(简单篇) http://www.sunboyu.cn/2008/06/13/centos5%e5%ae%89%e8%a3%85%e6%8c%87%e5%8d%97%ef%bc%88%e7%ae%80%e5%8d%95%e7%af%87%ef%bc%89.shtml http://www.sunboyu.cn/2008/06/13/centos5%e5%ae%89%e8%a3%85%e6%8c%87%e5%8d%97%ef%bc%88%e7%ae%80%e5%8d%95%e7%af%87%ef%bc%89.shtml#comments Fri, 13 Jun 2008 13:50:17 +0000 admin http://www.sunboyu.cn/?p=87

进入默认页面,直接回车即可

测试光盘文件的完整性,我一般都跳过

直接下一步

我一般都选择英文,因为命令行里好像不很支持中文

格盘,yes即可。注意:这里是在虚拟机或者一个空机器上进行安装,如果你在其他操作系统上安装双系统,此操作危险!

NEXT,使用默认的即可

YES,继续

分配IP地址,或者使用dhcp,此知识点不懂的话,不归本文管。

设置系统时区,一般用UTC,虽然有时候会用东八区。

设置root帐号的密码

选择定制安装或者是定制安装,当然我们要定制安装。

选择Development中的Development Libraries,Development Tools

选择Base System中的Base和Legacy Software Support

选择这四个,其他的就都不要选了,需要的话再慢慢装。

NEXT开始安装

装完,重启

root登录

这样安装AMP(APACHE MYSQL PHP)即可

]]>
http://www.sunboyu.cn/2008/06/13/centos5%e5%ae%89%e8%a3%85%e6%8c%87%e5%8d%97%ef%bc%88%e7%ae%80%e5%8d%95%e7%af%87%ef%bc%89.shtml/feed
centos5安装nginx+mysql+php fastcgi模式 http://www.sunboyu.cn/2008/05/18/centos5%e5%ae%89%e8%a3%85nginx%ef%bc%8bmysql%ef%bc%8bphp-fastcgi%e6%a8%a1%e5%bc%8f.shtml http://www.sunboyu.cn/2008/05/18/centos5%e5%ae%89%e8%a3%85nginx%ef%bc%8bmysql%ef%bc%8bphp-fastcgi%e6%a8%a1%e5%bc%8f.shtml#comments Sun, 18 May 2008 04:20:01 +0000 admin http://www.sunboyu.cn/?p=9 原教程 http://blog.s135.com/read.php/314.htm

安装环境:centos5.0 基本系统+开发工具

安装xml组件
yum install libxml2 libxml2-devel

编译安装 php
./configure –enable-fastcgi –enable-force-cgi-redirect
make && make install
————————————————————————–
[root@localhost php-5.2.5]# make install
Installing PHP SAPI module: cgi
Installing PHP CGI binary: /usr/local/bin/
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/man/man1/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Console_Getopt - installed: 1.2.3
[PEAR] Archive_Tar - installed: 1.3.2
[PEAR] Structures_Graph- installed: 1.0.2
pear/PEAR can optionally use package “pear/XML_RPC” (version >= 1.4.0)
[PEAR] PEAR - installed: 1.6.1
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
Installing PDO headers: /usr/local/include/php/ext/pdo/
————————————————————————–
make test

yum安装mysql
yum install mysql mysql-devel mysql-server

复制spawn-fcgi 至 /usr/local/bin/
chmod +x spawn-fcgi

/usr/sbin/groupadd www -g 48
/usr/sbin/useradd -u 48 -g www www
使用spawn-fcgi监听127.0.0.1的10080端口 进程10 用户www
————————————————————————–
[root@localhost bin]# spawn-fcgi -a 127.0.0.1 -p 10080 -C 10 -u www -f php-cgi
X-Powered-By: PHP/5.2.5
Content-type: text/html
spawn-fcgi.c.211: child exited with: 0, Success
————————————————————————–
[root@localhost bin]# spawn-fcgi -a 127.0.0.1 -p 10080 -C 10 -u www -f php-cgi
spawn-fcgi.c.190: child spawned successfully: PID: 27936
————————————————————————–
安装pcre
yum install pcre pcre-devel
编译安装 nginx
./configure –user=www –group=www
————————————————————————–
Configuration summary
+ threads are not used
+ using system PCRE library
+ OpenSSL library is not used
+ md5 library is not used
+ sha1 library is not used
+ using system zlib library
nginx path prefix: “/usr/local/nginx”
nginx binary file: “/usr/local/nginx/sbin/nginx”
nginx configuration file: “/usr/local/nginx/conf/nginx.conf”
nginx pid file: “/usr/local/nginx/logs/nginx.pid”
nginx error log file: “/usr/local/nginx/logs/error.log”
nginx http access log file: “/usr/local/nginx/logs/access.log”
nginx http client request body temporary files: “/usr/local/nginx/client_body_temp”
nginx http proxy temporary files: “/usr/local/nginx/proxy_temp”
nginx http fastcgi temporary files: “/usr/local/nginx/fastcgi_temp”
————————————————————————–
make && make install

touche /usr/local/nginx/conf/fcgi.conf
内容为
————————————————————————–
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with –enable-force-cgi-redirect
#fastcgi_param REDIRECT_STATUS 200;
————————————————————————–
启动 nginx
ulimit -SHn 51200
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

配置开机自动启动Nginx + PHP
vi /etc/rc.local
在末尾增加以下内容:
ulimit -SHn 51200
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 10080 -C 64 -u www -f /usr/local/bin/php-cgi
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

优化Linux内核参数
vi /etc/sysctl.conf
在末尾增加以下内容:
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000

使配置立即生效:
/sbin/sysctl -p
在不停止Nginx服务的情况下平滑变更Nginx配置
修改/usr/local/nginx/conf/nginx.conf配置文件后,请执行以下命令检查配置文件是否正确:
/usr/local/webserver/nginx/sbin/nginx -t

这时,输入以下命令查看Nginx主进程号:
ps -ef | grep “nginx: master process” | grep -v “grep” | awk -F ‘ ‘ ‘{print $2}’

至于日常维护,还不太清楚,咱们下次分解

—————————————————–
Nginx的编译参数如下:
[root@localhost]#./configure –prefix=/usr/local/server/nginx –with-openssl=/usr/include \
–with-pcre=/usr/include/pcre/ –with-http_stub_status_module –without-http_memcached_module \
–without-http_fastcgi_module –without-http_rewrite_module –without-http_map_module \
–without-http_geo_module –without-http_autoindex_module

]]>
http://www.sunboyu.cn/2008/05/18/centos5%e5%ae%89%e8%a3%85nginx%ef%bc%8bmysql%ef%bc%8bphp-fastcgi%e6%a8%a1%e5%bc%8f.shtml/feed