Home > Backend Development > PHP Tutorial > PHP调试小技巧

PHP调试小技巧

WBOY
Release: 2016-06-23 13:31:20
Original
1036 people have browsed it

在开发机环境只能只能使用VIM和Emacs(我用的是Emacs),调试PHP没有什么比较的工具,下面是我常用的一个函数:

file_put_contents('/tmp/my.log', print_r(array(date('Y-m-d H:i:s'), __LINE__, __METHOD__, ), TRUE)
Copy after login

该函数可以向/tmp/my.log文件输出一条日志,包括函数执行的日期、在哪一行执行、由哪个方法执行, 在__METHOD__之后可以加上我们想打印的变量,比如$a,然后就像下面这样:

file_put_contents('/tmp/my.log', print_r(array(date('Y-m-d H:i:s'), __LINE__, __METHOD__, $a), TRUE), FILE_APPEND | LOCK_EX);
Copy after login

然后我们重新运行代码,同时新开一个窗口,监视日志变化:

$ tailf /tmp/my.log
Copy after login

这样我们就可以打印出$a变量了。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template