Home > Backend Development > PHP Tutorial > Steps to build a PHP server debugging environment using Zend Studio+PHPnow+Zend Debugger_PHP Tutorial

Steps to build a PHP server debugging environment using Zend Studio+PHPnow+Zend Debugger_PHP Tutorial

WBOY
Release: 2016-07-13 10:40:46
Original
787 people have browsed it

本人主要是做ASP.NET开发的,但有时候也会接触到PHP,而且我认为PHP有很多源码值得学习,我们不是学习PHP代码的写法,而是学习源码的实现思路,或者免强叫为算法。

作为一名非专业的PHP开发者,想要较方便地读懂并搞清楚一个PHP功能模块的运行细节,搭建一个PHP调试环境,然后单步调试程序,以掌握程序的整个运行过程显的尤为重要。

一、 准备安装文件

1、PHPnow-1.5.6。“PHPnow 是 Win32 下绿色免费的 Apache + PHP + MySQL 环境套件包。简易安装、快速搭建的 PHP 环境。”

2、ZendDebugger-5.2.14。Zend公司的PHP调试工具或叫插件。 http://downloads.zend.com/pdt/server-debugger/ZendDebugger-5.2.14-cygwin_nt-i386.zip

3、ZendStudioEnterpriseEdition-v5.5.0。据说PHP业界最著名的IDE,不知道基于Eclipse插件的PHP开发环境如何,有时间玩一下再说。

二、 配置程序

1、安装PHPnow。把安装包PHPnow-1.5.3.zip解压到一个地方,像我这里解压到“D:\soft\PHP”,然后双击PHP文件夹中的“Setup.cmd”开始安装,中间安装到MySql的时候会提示你输入数据库用户名和密码,本地测试用一般就都设为“root”。安装完成后在浏览器输入以下地址http://127.0.0.1/,如果成功的话,你将会看到如下画面:

注意:如果你的系统之前有安装IIS,并且IIS是运行着的,要先把IIS停止掉,不然80端口会冲突,虽然通过“PnCp.cmd”工具可以修改Apache端口,但不建议这样改。

2、安装ZendDebugger。把ZendDebugger-5.2.14-cygwin_nt-i386.zip解压到PHPnow安装目录,即“D:\soft\PHP”,然后把ZendDebugger-5.2.14RC9-cygwin_nt-i386文件夹名字改成ZendDebugger这样短文件名,进到ZendDebugger目录,我们可以看到下面那样的文件结构:

现在要把文件夹中的X_X_x_comp文件夹重命名为php-X.X.x,比如将“5_2_x_comp”重命名为“php-5.2.x”,因为我的测试环境都是php5.2的,所以我可以只改“5_2_x_comp”这一个文件夹。这里的改动是为了等一下在php.ini中配置它。

现在去PHP安装目录修改PHP配置文件,这个文件通常被命名为“php.ini”,让服务器能正确加载我们的模块。但是这个PHPnow环境下的PHP配置文件不叫“php.ini”,而是“php-apache2handler.ini”,我们怎么可以知道当前WEB服务器所用PHP的配置文件名呢。下面就是一个办法:在“D:\soft\PHP\htdocs”目录,建立一个phpinfo.php文件,并在其中输入内容“”,然后打开浏览器可以看到如下信息,反白显示路径就是当前PHP配置文件所在路径了:

注意:这里指的PHP配置文件是网站依赖的PHP配置文件,不是下面提到的Zend Studio目录下的php.ini文件(Zend Studio也自带了几个不同版本的PHP),如下图:

修改“D:\soft\PHP\php-5.2.9-2-Win32\php-apache2handler.ini”文件。用记事本打开该文件,移动侧栏滚动条至最底部,在文档尾部可以发现以下配置节点:

在其尾部追加:

zend_extension_manager.debug_server_ts="D:\soft\PHP\ZendDebugger"
zend_debugger.allow_hosts=127.0.0.1/32,192.168.0.8/24
zend_debugger.expose_remotely=always

最终应该像这样:

解释一下:

(1);zend_extension_ts="D:\soft\PHP\ZendDebugger\5_2_x_comp\ZendDebugger.dll"这是我注释的,因为这样设置zend_extension_ts重复,出现不能与ZendOptimizer共存情况。

(2)、zend_extension_manager.debug_server_ts="D:\soft\PHP\ZendDebugger",这里指到目录就行了,PHP会自动根据自己版本去下面找php_X_X_X这样文件夹下面的dll文件,这也是上面我们为什么要对ZendDebugger下面子目录改名的原因。

(3)、zend_debugger.allow_hosts=127.0.0.1/32,192.168.0.8/24,这里后面的192.168.0.8改成你自己的IP就行了,可以像下面那样查看到自己的IP地址:

The following "32" and "24" do not need to be changed. They are not directory names, but subnet mask type codes. "32" represents "255.255.255.255" and "24" represents "255.255.255.0".

Open in the browser: http://127.0.0.1/phpinfo.php. If you can see the following information, the installation is successful. Pay attention to the last line "with Zend Debugger v5.2.14, Copyright (c) 1999-2008 , by Zend Technologies”. Returning to http://127.0.0.1/, we found that the Zend Optimizer support status in the component support box is still "Yes", which means that our Zend Debugger and Zend Optimizer are coexisting and running (there are many tutorials on the Internet that do not coexist and run, which is not enough Perfect).

3. Install Zend Studio. Unzip ZendStudioEnterpriseEdition-v5.5.0.270.rar, execute the win_setup.exe file after decompressing the file, and click Next all the way by default. This will successfully install Zend Studio on the C drive. Run it and then close it, because the default is English, let's change it to Chinese. On drive C (the drive where Zend Studio is installed), search for the file "desktop_options.xml", as shown below.

After finding it, open it with notepad and find:


 

Change the above en to zh and save it, then mark the file as "read-only" (Zend Studio will automatically restart at a certain time and change it back to the default settings. If it is set to "read-only", it will not be able to do anything). In addition, the encoding options like the following can also be modified according to the actual situation:


 

For example, you can change it to . You can modify this option when you open the code file with Zend Studio and find Chinese garbled characters.

3. Start debugging

Find "Zend Development Environment (Zend Studio)" from the "Start Menu" and run it. Create a new project and introduce a developed source code package into this project. My source code package is in "D:softPHPhtdocscms". This cms is the SupeSite7.0 program. In the debugging options of the new project, set it as shown below, where The Debug Server URL can also be an address like 127.0.0.1, as long as a few settings are synchronized:

 

In addition, the "Debug" label of "Tools" menu "Preferences" is also set as shown below:

Check it out now:

If successful, the "Successfully connected to Debug Server." dialog box will be displayed.

Open the SupeSite7.0 source code project, select the built-in browser of Zend Studio, and enter in the address bar: http://127.0.0.1/cms/ batch.search.php. Here I demonstrate the search page code of SupeSite7.0 debug. Now you directly press the "Scale Insect" button on the far left of the browser (you can select different debugging ranges from the inverted triangle next to it) and directly enter the batch.search.php page debugging (if the batch.search.php page was not in the editing state before, that is If it has not been opened, direct debugging will be opened automatically. In addition, if you use F11 to execute statement by statement, the external code file contained in the current debugging page will also be opened

.

After pressing the debug button, go directly to the source code, and the cursor is positioned on the first statement (I did not set a breakpoint here and debugged the program in F5 mode), like the following:

Now let’s test clicking a button to submit the form value and capture it. As shown in the picture below, click the "Search" button to see how the keyword "What is CMS?" is processed. Your operation sequence must be like this: Open http://127.0.0.1/cms/batch.search.php—>Enter the keyword "What is CMS?"—>Click the "Search" button—>Click Browser Tools "Scale Insects" button in the bar.

After debugging, we can see what variables "What is CMS ?" are stored in and processed. As shown below:

At this point, the entire Zend Studio+PHPnow+Zend Debugger server debugging environment has been set up and the usage has been demonstrated.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/714946.htmlTechArticleI mainly do ASP.NET development, but sometimes I also come into contact with PHP, and I think PHP has A lot of source code is worth learning. We are not learning how to write PHP code, but learning how to implement the source code...
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