用phpstorm+xdebug调试php代码,网上所有的教程都是调试单个php文件,如
<?php
$i = $i+1;
?>
这种形式,这样的调试很容易,照着教程说的一步步设php.ini,设置Phpstorm的debug,下载个firefox插件easiest xdebug就行了,关键是html和php代码混编的,形如:
<?php
/**
* Created by PhpStorm.
* User: yWX368381
* Date: 2016/10/19
* Time: 14:13
*/
session_start();
header("Content-Type: text/html; charset=utf-8");
if($_POST["Submit"]!="")
{
$check = $_POST["checks"];
xdebug_break();
if ($check=="")
{
echo "<script>alert('验证码不能为空');window.location.href='index_check.php';</script>";
}
if ($check==$_SESSION[check_checks])
{
echo "<script>alert('用户登录成功');window.location.href='index_check.php';</script>";
}
else
{
//echo "<script> alert('验证码不正确');window.location.href='index_check.php';</script>";
echo "<script>alert(\"验证码不对,正确的是:".$_SESSION[check_checks]."\");window.location.href='index_check.php';</script>";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>rand函数的应用</title>
<style type="text/css">
开始我是死活也调试不了,断点不起作用,后来发现原来我的xdebug模块根本就是没有被Php加载成功,原来调试混编和调试单个文件都一样,只是不同的是混编的或嵌入的应该属于remote_debug,
1.首先php.ini要设置好,保证xdebug能正确加载,即phpinfo()能显示xdebug模块。我的php.ini是这样设置的
[XDebug]
xdebug.auto_trace = on
xdebug.collect_params = 1
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir ="D:\phpStudy\tmp\xdebug"
xdebug.trace_output_dir ="D:\phpStudy\tmp\xdebug"
xdebug.profiler_output_name = "cache.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "192.168.0.198" //IP最好设成自己的IP,如果是多人办公用wifi的情况下,自己在家可以127.0.0.1
xdebug.remote_port=10001
xdebug.idekey=PHPSTORM
zend_extension="D:\phpStudy\php53\ext\xdebug.dll"
我的不显示是zend_extension="D:\phpStudy\php53\ext\xdebug.dll"注掉了,phpstorm刚开始提示xdebug被反复加载,当时注掉这一句不提示报错了但导致php不能加载xdebug的恶果。
<?php
$i = $i+1;
?>
这种形式,这样的调试很容易,照着教程说的一步步设php.ini,设置Phpstorm的debug,下载个firefox插件easiest xdebug就行了,关键是html和php代码混编的,形如:
<?php
/**
* Created by PhpStorm.
* User: yWX368381
* Date: 2016/10/19
* Time: 14:13
*/
session_start();
header("Content-Type: text/html; charset=utf-8");
if($_POST["Submit"]!="")
{
$check = $_POST["checks"];
xdebug_break();
if ($check=="")
{
echo "<script>alert('验证码不能为空');window.location.href='index_check.php';</script>";
}
if ($check==$_SESSION[check_checks])
{
echo "<script>alert('用户登录成功');window.location.href='index_check.php';</script>";
}
else
{
//echo "<script> alert('验证码不正确');window.location.href='index_check.php';</script>";
echo "<script>alert(\"验证码不对,正确的是:".$_SESSION[check_checks]."\");window.location.href='index_check.php';</script>";
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>rand函数的应用</title>
<style type="text/css">
开始我是死活也调试不了,断点不起作用,后来发现原来我的xdebug模块根本就是没有被Php加载成功,原来调试混编和调试单个文件都一样,只是不同的是混编的或嵌入的应该属于remote_debug,
1.首先php.ini要设置好,保证xdebug能正确加载,即phpinfo()能显示xdebug模块。我的php.ini是这样设置的
[XDebug]
xdebug.auto_trace = on
xdebug.collect_params = 1
xdebug.profiler_append = 0
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 0
xdebug.profiler_output_dir ="D:\phpStudy\tmp\xdebug"
xdebug.trace_output_dir ="D:\phpStudy\tmp\xdebug"
xdebug.profiler_output_name = "cache.out.%t-%s"
xdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "192.168.0.198" //IP最好设成自己的IP,如果是多人办公用wifi的情况下,自己在家可以127.0.0.1
xdebug.remote_port=10001
xdebug.idekey=PHPSTORM
zend_extension="D:\phpStudy\php53\ext\xdebug.dll"
我的不显示是zend_extension="D:\phpStudy\php53\ext\xdebug.dll"注掉了,phpstorm刚开始提示xdebug被反复加载,当时注掉这一句不提示报错了但导致php不能加载xdebug的恶果。
2. 设置下phpstorm Run->Edit Configuration... 我的网站目录是hello, 想启动调试的页面是从index_check.php开始的,启动debug时会先执行这个页面,即使断点不在这个页面也没关系,如断点设在了index_check.php的后台check.php,照样也能断下来
3.好,执行 Run->debug daidai吧 (daidai是上图我为这次调试起的名字)