原创文章,转载请指明出处并保留原文url地址
前面,我们安装了php的开发环境xampp, 安装了wordpress程序,然后配置了php的调试环境, 以及 用Nginx url重写及NuSphere环境调试windows live writer客户端 等文章通过这些我们基本上打造了一个可以调试的、完善的php调试程序的开发系统。
本文我们要解决的问题是:全面记录nginx的url重写(rewrite)后的数据, 以及windows live writer 在发布文章过程中都发布了那些数据,通过这些数据的分析,了解xml rpc的工作过程。
1. tcpTrace记录数据的工作原理
系统网络结构以及相关组件的配置情况如下:
存在两台服务器, 192.168.186.162和192.168.186.163
163上部署nginx程序
162上部署tcptrace、xampp、wordpress、PhpED等软件
同时修改162服务器的hosts文件如下
通过修改了hosts文件, 这样在wlw在发布文章到www.iigrowing.cn时,根据hosts文件中配置的域名, 把数据发送给163的nginx服务器, nginx服务器在内部判断url中是否存在php的调试参数, 若是没有则重写url(添加一个php的调试标志),然后通过nginx的代理功能(proxy_pass)将请求发给162服务器的9999端口, 在9999端口上tcpTrace正在接受用户请求, 接受到请求后将请求信息打印到调试窗口, 然后将请求在转发给后端的apache服务器,apache服务器将php请求转给wordpress。 WordPress在工作过程中, PhpED环境监控着php系统,当发现有请求进入时,就进入调试模式,便于我们调试程序,发现问题。
2. 关于tcptrace
http://www.pocketsoap.com/tcpTrace/
TcpTrace
I got fed up with installing Java & Apache SOAP just to get tcpTunnelGUI, so here’s a native Win32 version, built using Attila (no MFC ). It started out as a copy of the Apache tool, but has taken on a life of its own!.
Huh, it does what ?
Basically you use it as a tunnel between your client & server. Start tcptrace.exe and up comes a dialog box asking for local port #, destination server, and destination port # (Ignore the logging options for now) Fill these in, click Ok, and wow are you going to have fun. For example if you are writing a client and testing against a remote server (say www.razorsoft.net ), you can setup
Local Port # 8080
Destination Server www.razorsoft.net
Destination Port # 80
Now configure your client so that it thinks the server is at localhost:8080. tcpTrace will forward all the traffic from localport:8080 to the remote server (and vica versa), dumping the contents in the process. If you are hosting a server say on port 80 and want to use it, then change your server to run on port 81, and setup
Local Port # 80
Destination Server localhost
Destination Port # 81
you can now see your incoming traffic.
It should work with all the text based IP protocols, I’ve been using it with SOAP (port 80) & HTTP (port 80), and I know Peter Drayton has been using it with POP3 (port 110) & SMTP (port 25
3. php数据跟踪环境的基本环境需求
a) Php环境, 选择xampp软件环境,方便安装测试。关于如何利用xampp软件安装php,参见:XAMPP安装及使用概述
b) WordPress系统安装方法参考: WORDPRESS安装
c) Phped调试环境 基于NuSphere环境调试wordpress系统
d) Windows下nginx Windows XP下Nginx的安装与配置
e) TcpTrace,
4. 配置tcptrace并启动环境
运行tcptrace程序, 显示相关配置窗口, 按照下图进行相关配置
配置完成后, 点击ok按钮完成相关工作,并且tcptrace程序也已经启动,可以开始工作。
5修改windows下的nginx配置文件
1)进入conf目录, 打开nginx.conf文件,修改配置文件
修改图中紫色部分的配置为:9999端口, 就是tcptcace要监控的端口
2)启动windows下的nginx系统
6. 启动192.168.186.162服务器的PhpED环境
启动后,会启动php调试的监听程序, 如下图
如监听程序没有启动则需要重新配置php的调试环境
7. 配置192.168.186.162服务器
1)启动windows live writer程序, 配置成如下:
2) 用户wlw创建新blog文章
如上图, 写好文章的标题, 及内容, 然后点击发布按钮
3) 观察tcpTrace显示信息
4) 从tcptrace中记录的, 从windows live writer写出的数据如下
POST /xmlrpc.php?DBGSESSID=413693790766000002;d=1,p=1,c=0& HTTP/1.0
Host: 192.168.186.162:9999
Connection: close
Accept: */*
Accept-Language: zh-CN, en-US, en, *
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Windows Live Writer 1.0)
Content-Type: text/xml
Content-Length: 1647
<?xml version=”1.0″ encoding=”utf-8″?>
<methodCall>
<methodName>metaWeblog.newPost</methodName>
<params>
<param>
<value>
<string>1</string>
</value>
</param>
<param>
<value>
<string>admin</string>
</value>
</param>
<param>
<value>
<string>admin</string>
</value>
</param>
<param>
<value>
<struct>
<member>
<name>title</name>
<value>
<string>tt1</string>
</value>
</member>
<member>
<name>description</name>
<value>
<string><p>content 1234567890 </p> <p>abcdefg</p></string>
</value>
</member>
<member>
<name>mt_text_more</name>
<value>
<string />
</value>
</member>
<member>
<name>mt_keywords</name>
<value>
<string />
</value>
</member>
<member>
<name>wp_slug</name>
<value>
<string />
</value>
</member>
<member>
<name>mt_basename</name>
<value>
<string />
</value>
</member>
<member>
<name>wp_password</name>
<value>
<string />
</value>
</member>
<member>
<name>categories</name>
<value>
<array>
<data />
</array>
</value>
</member>
<member>
<name>mt_excerpt</name>
<value>
<string />
</value>
</member>
</struct>
</value>
</param>
<param>
<value>
<boolean>1</boolean>
</value>
</param>
</params>
</methodCall>
WordPress对xmp rpc调用的相应
从数据中我们可以知道一个 典型xml rpc的工作过程, 里面都是xml代码,具体内容大家慢慢分析吧, 比较简单。
5) WordPress的http相应
如下代码是 从tcptrace中获取的相关相应
HTTP/1.1 200 OK
Date: Thu, 25 Apr 2013 03:13:02 GMT
Server: Apache/2.2.14 (Win32) DAV/2 mod_ssl/2.2.14 OpenSSL/0.9.8l mod_autoindex_color PHP/5.3.1 mod_apreq2-20090110/2.7.1 mod_perl/2.0.4 Perl/v5.10.1
X-Powered-By: PHP/5.3.1
Set-Cookie: DBGSESSID= ; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT; version=1
Set-Cookie: DBGSESSID= ; path=/; version=1
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Connection: close
Content-Length: 161
Content-Type: text/xml
<?xml version=”1.0″?>
<methodResponse>
<params>
<param>
<value>
<string>803</string>
</value>
</param>
</params>
</methodResponse>
8. 查看192.168.186.162的调试环境
由于本次主要是为了检测 xml rpc调用过程中的信息, 因此取消了调试器中的断点,因此程序没有在调试器中中断。
但是调试的日志中还是有相关的记录的如下:
只是由于没有中断运行因此我们可以不用关心相关过程。
9. 查看其他过程
另外我们也可以监控一下,windows live writer的配置过程, 如下图, 过程比较多,我们就给数据了,大家自己练习吧。