Friday, April 23, 2010

blog 新地址

blog换成了wordpress,又舍不得pylogs,还是启用新址吧:
http://www.lvscar.info/blog/

Tuesday, June 16, 2009

Tuesday, March 31, 2009

ZendStudio 调试环境配置

环境:

*. ubuntu(x86) 8.04
*. php 5.2.4
*. ZendStudio 6.1.1
*. nginx(0.6.34) with fastcgi

步骤:

  1. Zend 下载页下载适用于你的系统和浏览器的Zend Debugger和Browser Toolbar
  2. 参考Zend Debugger 安装文档安装在php环境中集成zend debugger
    • php.ini中的配置
      zend_extension =  /your/env/path/ZendDebugger.so
      zend_debugger.allow_hosts= 127.0.0.1/32 , 127.0.0.1/24
      zend_debugger.connector_port = 10137
      zend_debugger.expose_remotely=allowed_hosts
  3. 安装浏览器工具条(Browser Toolbar)
    • 调试时,需要通过工具条让发送出的http请求包含特定参数
  4. 在Zend Studio Windows - Preferences - php- Debug - Installd Debugger 中检查client host/ip地址(127.0.0.1), debugger Port(10137)
  5. 重启fastcgi进程产生器. ($sudo /etc/init.d/php-fastcgi restart )
  6. 在Zend Studio run- Debug Configurations -PHP Web Page 下新建一个项目,进行适当配置后点击 Test Debugger.看是能够探测到Zend Debugger.
    • 如不成功,检查php.ini中的配置,并参考下文Tips章节.
  7. 在程序中打上断点.
  8. 点击浏览器 Zend 工具条 Debug右边的按钮,选中'All page on this site' (也可根据情况,只调试post请求).
  9. 尝试用浏览器触发前一步骤设置的断点.

Tips:

  • 可以用phpinfo(),查看ZendDebugger的安装情况.
  • 检查xdebug是否有安装,如果有安装会和zend debugger冲突. 卸载xdebug后还需注释掉 /etc/php5/conf.d/xdebug.ini中的内容
    • 我这里冲突的情况是,Zend studio 检测不到Debugger.并且访问任何php页面时报 "Debugger compile handler overriden, cannot continue".

参考链接:

TODO:

  • 解决当前环境调试时无法设置不在第一行停住(Break at First Line). (貌似要hack ff扩展 )

Tuesday, March 24, 2009

php app 避免sql注入(SQL Injection)攻击

  • 利用php内置 addslashes() 方法对用户输入的字符串进行处理 / 输入结果时用stripslashes() 取得原值。
  • 始终使用 mysqli::query 方法确保只会执行单条查询
    确定多条查询语句时,才采用 mysqli::multi_query
  • 利用 db->prepare() 通过sql模板进行查询
    • eg:
      $sql_templet = "update todo set info = ? where id = ?";
      $stmt = $this->db->prepare($sql_templet);
      $stmt->bind_param("si",$info,$id);
      $result = $stmt->execute();
  • 阅读"php and mysql web developmen"一书 Chapter 16章节时提到的
    mysqli::real_escape_string 方法也能起到addslashes()的作用,
    • 区别:
      • addslashes : quote ('), double quote ("), backslash () and NUL
      • mysqli::real_escape_string NUL (ASCII 0), \n, \r, \, ', ", and Control-Z.
        除此之外,real_escape_string 还能起到转编码的作用。

php On Nginx Fastcgi

系统环境

  • ubuntu 8.04
  • php-cgi 5.2.4
  • nginx 0.6.34
  • lighttpd 1.4.19 (需要其中的 spawn-fcgi 程序)

相关概念和链接

  • fastcgi

    相对于cgi为每个动态内容请求创建一个独立的进程,fastcgi能使用一个单独进行为多个动态内容请求进行相应

    wikipeida中的fastcgi条目

安装过程

apt-get install xxxx

配置备注

nginx配置

  1. 备份nginx默认站点配置文件(/etc/nginx/sites-available/default) 或 以default为模板创建新文件并在 /etc/nginx/sites-enabled/ 中建立链接
  2. 修改站点配置文件中" location /" 起始段落为以下内容
    location / {
    #root /var/www/nginx-default;
    root /home/lvs/code/php/virtual_host/chino/wwwroot ; #指向php工程DocumentRoot目录
    index index.php index.html index.htm ; #添加index.php为站点默认访问索引文件
    }
  3. 修改站点配置文件中"location ~ \.php " 起始段落为以下内容
    location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000; #这个地址需要和fastcgi监听地址匹配
    fastcgi_index index.php;
    include /etc/nginx/fastcgi_params;
    fastcgi_param SCRIPT_FILENAME /home/lvs/code/php/virtual_host/chino/wwwroot$fastcgi_script_name;
    #fastcgi_param 中,fastcgi_script_name前的值应设置为php工程 DocumentRoot
    #TODO 需要找到以变量存储php 工程 DocumentRoot的方法
    }

fastcgi环境建立

1. 创建 php fastcgi监听进程生产 脚本

    • $sudo touch /usr/bin/php-fastcgi && 插入以下内容
      #!/bin/sh
      spawn-fcgi -a 127.0.0.1 -C 7 -p 9000 -u www-data -f /usr/bin/php5-cgi
      #如果不安装lighttpd,可以下载lighttpd源码编译后提取spawn-fcgi程序
      #指定产生7个 fastcgi 监听进程

2. 创建fastcgi 启动管理脚本

    • $sudo touch /etc/init.d/php-fastcgi-spawner && 插入以下内容
#!/bin/bash
PHP_SCRIPT=/usr/bin/php-fastcgi #需要和上一步骤中php fastcgi监听进程生产脚本位置匹配
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php5-cgi
RETVAL=$?
;;
restart)
killall -9 php5-cgi
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: php-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL

3. 如果需要系统启动自动运行:

    • debian系在/etc/rc2.d/ 中创建S字头链接
    • redhat系在/etc/rc3.d/ (文本环境 ) 或 /etc/rc5.d/ (图形环境) 创建链接

性能测试

以 $ab -c 50 -n 2000 对分别使用nginx&fastcgi和apache&mod-php 运行的同一php页面进行测试
apache 结果如下:

Server Software:        Apache/2.2.8
Server Hostname: localhost
Server Port: 80

Document Path: /index.php?module=todo&act=thread
Document Length: 11622 bytes

Concurrency Level: 50
Time taken for tests: 22.542643 seconds
Complete requests: 2000
Failed requests: 0
Write errors: 0
Total transferred: 23765490 bytes
HTML transferred: 23284290 bytes
Requests per second: 88.72 [#/sec] (mean)
Time per request: 563.566 [ms] (mean)
Time per request: 11.271 [ms] (mean, across all concurrent requests)
Transfer rate: 1029.52 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 23.0 0 156
Processing: 61 556 126.6 552 1421
Waiting: 1 539 127.7 531 1397
Total: 157 560 121.6 553 1421

Percentage of the requests served within a certain time (ms)
50% 553
66% 584
75% 611
80% 630
90% 695
95% 761
98% 871
99% 998
100% 1421 (longest request)

nginx结果如下

Server Software:        nginx/0.6.34
Server Hostname: localhost
Server Port: 8077

Document Path: /index.php?module=todo&act=thread
Document Length: 11622 bytes

Concurrency Level: 50
Time taken for tests: 5.945355 seconds
Complete requests: 2000
Failed requests: 0
Write errors: 0
Total transferred: 23626000 bytes
HTML transferred: 23244000 bytes
Requests per second: 336.40 [#/sec] (mean)
Time per request: 148.634 [ms] (mean)
Time per request: 2.973 [ms] (mean, across all concurrent requests)
Transfer rate: 3880.68 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 12.8 0 133
Processing: 12 144 26.2 144 309
Waiting: 10 138 25.9 137 302
Total: 32 146 22.3 144 309

Percentage of the requests served within a certain time (ms)
50% 144
66% 146
75% 149
80% 150
90% 155
95% 172
98% 230
99% 271
100% 309 (longest request)

参考链接

Friday, October 27, 2006

Update!!! Update!!!

Firefox / Ubuntu ......两大开源界的明星项目。 这两天相距正式发布了新版本。
不必多说 better become even better 。
学习 自由/开源 软件,你可能需要认同一种新的哲学观。
但使用像 firefox / ubuntu 这样的产品。你得到的是生活质量的提高。

firefox下载地址

ubuntu下载地址

Wednesday, October 25, 2006

blogspot又被封了??

今晚发现 bolgspot 又不能访问了, 真是GWF度假回来了?
由于我升级到了Blogger.com beta。 得到动态发布的代价是不能ftp发布到国内的镜像站点了。
在bogspot仍然被GWF期间,我的新地址:
http://lvscar.livejournal.com

Sunday, October 22, 2006

ati开源RADEON驱动双显支持

fglrx 驱动在edgy下表现相当令人失望,,,升级到edgy这几天 基本上各种恼人的问题都是fglrx造成的。

logout/suspend 时系统挂起;和openoffice 的冲突;......

除了眩目的xgl3D桌面外,fglrx 能给我的edgy带来的好处只剩下方便的双显支持了。

今天稍作研究后搞定了ati开源radeon驱动的双头显示支持。 效果完美,,甚至好于fglrx驱动。
第二显示器带来的屏幕扩展,很大程度可以替代 xgl3D桌面带来的工作效率提高(窗口透明和桌面重整)。

实现方法步骤如下:
升级到edgy
在 /etc/modules 里注释掉 fglrx
这里 下载xorg.conf 文件 替换 /etc/X11/xorg.conf #替换前做好备份

这个配置文件默认采用MergedFB2 扩展桌面,支持两个显示器不同分辨率。窗口/鼠标在两个显示器间移动时自动调整坐标。(对宽屏笔记本用户很重要)

如果你不需要在两个显示器间采用不同分辨率,可以在 ServerFlags 节中 把
Option "DefaultServerLayout" "MergedFB2Layout"
行换成
Option "DefaultServerLayout" "MergedFBLayout"

幸运的话重启X后就能完美的实现双显了。

如果你的主板/显卡在检测第二显示器时存在问题 (只有一个显示器被点亮)
你可以用如下方法解决:
如果你采用 MergedFBLayout 找到MergedFB 对应的 Device 节 (其中包含 Identifier "MergedFB ATI Technologies,....")
在其中添加这行
Option "MonitorLayout" "LVDS, CRT2"
如果你采用MergedFB2,以此类推,在MergedFB2 对应的Device节中添加上面一行。

保存文件,重启X

开源驱动虽然3d加速比不上fglrx,但在我这里 mplayer -vo gl 全屏时是没问题的。
最重要的,由fglrx引起的问题 全部解决。。。。
依靠linux的稳定性和永不挂起的休眠,以后重启机器除了升级内核外,我找不到其他理由。

Pure Opensource ,Genuine Linux 。。。。。