'these days 1 & 2 things'

good night, and good luck.








Pure joy is a serious matter.


Native Green
Anima
Thomas Chapin
...Thomas Chapin, one of the more exuberant saxophonists and band leaders in jazz, died in 1998 at Rhode Island Hospital in Providence. He was 40.

Monday, May 16, 2011

利用xdebug+emacs+geben调试php


emacs的php-mode对于编辑php已经十分方便了,但是调试php的时候要是能利用xdebug而不是echo来echo去,还要借助一些其他的工具。今天终于知道如何配置emacs下调试php的方法了,贴出来,作为自己学习php的一个起点吧。
前提是已经配置好lamp的开发环境。
接下来,
首先,要安装emacs,以及emacs的php-mode.el文件拷贝到某个目录比如/usr/share/emacs/23.2/lisp/php-mode.el,并加入如下配置到dotemacs中:

(require 'php-mode)
(add-to-list 'auto-mode-alist '("\\.module$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.inc$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.install$" . php-mode))
(add-to-list 'auto-mode-alist '("\\.engine$" . php-mode))
;;_+ php-mode

(define-key php-mode-map
[menu-bar php php-debug]
'("PHP Debug" . php-debug))
(define-key php-mode-map
[menu-bar php php-run]
'("Run PHP" . php-run))
(defun php-debug ()
(interactive)
(shell-command
(concat "php -l \"" (buffer-file-name) "\"")))
(defun php-run ()
(interactive)
(shell-command
(concat "php -q \"" (buffer-file-name) "\"")))
(defun my-php-mode()
;; 将回车代替C-j的功能,换行的同时对齐
(define-key php-mode-map [return] 'newline-and-indent)
(define-key php-mode-map [(control c) (r)] 'php-run)
(define-key php-mode-map [(control c) (d)] 'php-debug)
(interactive)
;; 设置php程序的对齐风格
(c-set-style "K&R")
;; 自动模式,在此种模式下当你键入{时,会自动根据你设置的对齐风格对齐
(c-toggle-auto-state)
;; 此模式下,当按Backspace时会删除最多的空格
(c-toggle-hungry-state)
;; TAB键的宽度设置为4
(setq c-basic-offset 4)
;; 在菜单中加入当前Buffer的函数索引
(imenu-add-menubar-index)
;; 在状态条上显示当前光标在哪个函数体内部
(which-function-mode)
)
(add-hook 'php-mode-hook 'my-php-mode)


其次,需要安装xdebug和xdebug for php

sudo apt-get install xdebug php5-xdebug


安装好xdebug以后,可以通过:

locate xdebug.so

找到xdebug.so的位置,我这里是:

/usr/lib/php5/20090626/xdebug.so

然后编辑/etc/php5/apache2/conf.d/xdebug.ini文件
加入:
[xdebug]
zend_extension=/usr/lib/php5/20090626/xdebug.so
xdebug.remote_enable=On
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_autostart=On
xdebug.remote_handler="dbgp"

再次,要安装geben到某个路径,例如:/usr/share/emacs/site-lisp/geben 并在dotemacs中加入如下配置:

(add-to-list 'load-path "/usr/share/emacs/site-lisp/geben")
(autoload 'geben "geben" "PHP Debugger on Emacs" t)
接着,编辑/etc/php5/apache2/php.ini文件,找到

;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;

部分,在下面加入:

zend_extension=/usr/lib/php5/20090626/xdebug.so

[debug]
; Remote settings
xdebug.remote_autostart=off
xdebug.remote_enable=on
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000

; General
xdebug.auto_trace=off
xdebug.collect_includes=on
xdebug.collect_params=off
xdebug.collect_return=off
xdebug.default_enable=on
xdebug.extended_info=1
xdebug.manual_url=http://www.php.net
xdebug.show_local_vars=0
xdebug.show_mem_delta=0
xdebug.max_nesting_level=100
;xdebug.idekey=

; Trace options
xdebug.trace_format=0
xdebug.trace_output_dir=/tmp
xdebug.trace_options=0
xdebug.trace_output_name=crc32

; Profiling
xdebug.profiler_append=0
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=0
xdebug.profiler_output_dir=/tmp
xdebug.profiler_output_name=crc32

接着重启apache:
sudo /etc/init.d/apache2 restart配置完成
然后,可以在浏览器中打开需要调试的页面,并在url地址后加上XDEBUG_SESSION_START=session_name,比如:
http://localhost/index.php?XDEBUG_SESSION_START=1然后回到emacs,打开该被调试的php文件,键入
M-x geben
开始调试。
geben的调试命令一览:
SPC geben-step-again
> geben-set-redirect
? geben-mode-help
B geben-breakpoint-menu
U geben-clear-breakpoints
b geben-set-breakpoint-line
c geben-run-to-cursor
d geben-show-backtrace
e geben-eval-expression
g geben-run
i geben-step-into
o geben-step-over
q geben-stop
r geben-step-out
t geben-show-backtrace
u geben-unset-breakpoint-line
v geben-display-context
w geben-where

C-x SPC geben-set-breakpoint-line

C-c C-c geben-run
C-c C-d geben-unset-breakpoint-line
C-c C-l geben-where
C-c C-n geben-step-over
C-c C-s geben-step-into
C-c C-t geben-set-breakpoint-line
C-c b geben-show-breakpoint-list
C-c f geben-find-file
C-c p geben-toggle-pause-at-entry-line-flag




Read Full Text...







別人的生活



幾個朋友

> 電痣

關于音樂

> The dead musicians directory

> Also, a place where the great minds buried

> WFIU - Public Radio from Indiana University

> Thomas Chapin

> dannyboy達人

> 小威老师

> 蘇重爵士

> 台北愛樂 (喜歡雷光夏、杨怡珊的小心了)

> lonesome music

> ORGY_IN_RHYTHM

> 芝加哥藝術合奏團

> advant-garde what?

> free music saloon

> 潛味音樂

> 启彬与凯雅的爵士栈

> NorwayMusic Nfo

> Jazz Age 1920

> another exciting place for jazz buff

> Categoried Selection!

讀書,閑逛

> 香港電台「網上廣播站」BBS

> 長的頭髮

> 德谟克拉西

> 中華讀書報

> 趣味の極道

> 知日部屋

> 何春蕤

> Miss Lee in Summer

> ada's reading diary

> 陳炯明研究

> 讀書圈

> 偽基百科

有趣兒的地方

> 插畫星期五

> ComicPedia

> 鬼佬無知才稀奇

> 中國,不特別

其他

> 少少豆瓣一下

> mytube