生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

PHPSTORM 确实是一款非常好用的生产力工具, 他的代码提示, 检错, 重构, 调试都非常的棒, 而且自带的文件历史功能好用的我都快哭了(帮我挽救了没来得及提交到git的代码), 其实phpstorm不只可以写php, 写javascript(包括node),html,css也是极好的, webstorm的功能他全部都有, 并且还有很多的好用的插件, 针对thinkphp的ThinkStorm,针对yii的yiistorm

phpstorm = idea.php + ssh tools(比如xshell) + http client(比如postman) + console tools

官方网站

https://www.jetbrains.com/phpstorm

环境说明:
php环境: phpstudy(php5.3以上, apache)

xdebug

使用xdebug可以非常方便的调试代码, 找出错误, 其实除了找出错误还可以很方便的走框架流程或者学习第三方sdk, 运行到内部看他是怎么写的

启用xdebug插件

  • 右键点击右下角的phpstudy, PHP扩展及设置>PHP扩展>Xdebug 勾上
  • 右键点击右下角的phpstudy, 打开配置文件>php-ini,找到xdebug的配置项,保证有以下的配置
; XDEBUG Extension
zend_extension="C:\application\phpStudy\php53\ext\xdebug.dll"
;此路径和你的安装phpstudy目录有关哦
[xdebug]
xdebug.remote_enable = On
xdebug.remote_handler=dbgp
xdebug.remote_host= 127.0.0.1
xdebug.remote_port = 9000
xdebug.idekey="PHPSTORM"

请求附上xdebug启动session

下面3种方法3选一, 官方的原话是get, post, cookie都可以附, chrome扩展是cookie
具体使用哪种方法根据实际情况选择, 高兴就好

chrome安装Xdebug helper扩展

进入chrome网上应用商店, 搜索&安装 Xdebug helper

启用调试

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

在请求的参数里面

在请求的参数上加上XDEBUG_SESSION_START=1, 如

http://test.xxx.mobi/wap/test?XDEBUG_SESSION_START=1
http://test.xxx.mobi/wap/test?XDEBUG_SESSION_START=1#/index

在入口文件, 如index.php 开头添加如下语句

$_GET['XDEBUG_SESSION_START'] = 1;

或者

$_POST['XDEBUG_SESSION_START'] = 1;

打断点, 启动监听

最新版2017.1以上的ps已经不需要配置了,不需要配置了, 配置的时候会提示PhpStorm will listen for all incoming debug connections and detect configuration.... 反正就是zero-configuration, 都提示了可以不配置就不要搞事情了, 直接启动监听就行了, 当然配置了也没毛病,

1.确保phpstorm里面xdebug的port也是9000(同wamp的xdebug端口) : File>Setting在搜索框里面搜索xdebug, 这个端口请注意, 如果你使用的nginx + php-fpm, 那么9000端口可能会被php-fpm占用, 请更换端口, 如9001

2.在网站目录下新建一个目录test, 用phpstorm在这个目录下新建一个项目,并新建一个index.php文件,内容如下

<?php
    $a = 'Hello ';
    $b = 'phpstorm';
    echo $a . $b;
?>

在$b…那一行打一个断点,就是在行号后面点一下,就会有一个暗红的点里面还有一个勾出来

3.在phpstorm工具栏的, Run>Edit Configurations, 跟着我配置,此步为可选, 新版本不需要配置

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

4.启动监听

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》
这两者缺一不可,现在已经不是缺一不可了,启动监听才是不可缺少的

注意每次重新启动phpstorm都要
重新启动监听

启动debug

确保下面的配置

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

在浏览器中访问http://localhost/test/

在phpstorm中就会有如下的反应,具体如下图

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

  1. Show execution point 定为到断点处
  2. Step over下一条语句
  3. Step into 进入函数
  4. Force step into 强行进入
  5. Step out
  6. Run to cursor 运行到光标处
  7. Frames 显示调用的文件
  8. Resume program
  9. Stop
  10. View Breakpoints
  11. Mute Breakpoints
  12. console 这个必须要好好讲一下,可以直接写php代码,但你还没有释放调试,你可以尝试在console处输入以下的代码,你会发现,输入的代码实时的反馈到了内存
$a = "suprise";

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

enjoy it

Database

连接

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》
《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

使用 – 图形化方式

点击刚才创建的数据库, 右键 > synchronize
《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》
双击右边的表,就可以打开一个表的实例

使用 – 命令行形式

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

  1. 进入命令行的按钮
  2. 命令输入窗,按CTRL+ENTER执行
  3. 查询结果窗

FTP on PhpStorm

配置

参数设置

Tools>Deployment(部署)>Configuration(配置)> + (右上角, 输入名字), 如下图

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

  1. 输入帐号信息, 注意保存密码
  2. 在高级选项中一定要勾选Always use LIST command,我在windows下是吃尽了苦头

    不然会报错Connection to '*'failed. Invalid descendent file name "/",如下图

    《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

  3. 测试连接, 如果勾上了Always use LIST command

    《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

映射设置

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

上传文件

你可以在这里查看修改的文件, 并只上传修改的文件

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

更多的文件操作

请自己发现右键菜单或者其他菜单上面的Deployment选项操作

Git on PhpStorm

只建议有Git经验的人阅读, 至少简单的Git操作要会(新建仓库, 提交修改, push)如果本身就是一个git的项目,ps会自动识别出来, 如果不是的话, 可以手动导入Git项目,

下面有一个典型的Version Control的选项卡

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

  1. 普通的commit是要先add再commit, 用了ps直接用commit吧
  2. 把修改的内容丢弃掉
  3. 差异对比
  4. 上传到FTP, 如果你配置了FTP的话
  5. 显示历史,ps提供了一个本地的文件历史管理, 有时候能救你一命
  6. 一些不常用的操作
  7. 仓库的操作

    • Git branch/merge/clone/fetch/pull/push/rebase

http client

这个工具临时或者偶尔使用还是可以的, 如果需要批量使用, 推荐postman
如果要使用请打开Tools > Test RESTful Web Service

请求配置

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》
<1> 提交请求
<2> 调试提交请求, 可以配合xdebug使用, 可以断点, 其实就是在cookie中加入XDEBUG_SESSION:PHPSTORM
<3> 历史
<4> 导出
<5> 导入
<6> 产生认证头
<7> 配置http代理
《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

响应

《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》
左边有格式化请求
支持格式化json, xml, html, text

ssh工具

Tools > Deployment > Browse Remote Host

在Remote Host 标签下面添加
《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》

Tools > Start SSH Session(可以设置为快捷键) 选择刚才加入的ssh server

scratches 抓板/猫抓板

什么动物需要抓板, 猫才需要抓板啊, 我觉得叫猫抓板没毛病
快捷键 ctrl + shift + alt + Insert, 调出新建猫抓板, 里面抓板很多, 可以输入字母搜索
介绍几个常用的抓板

http client

具体使用参考
Tools > Open HTTP Requests Collection
《生产力工具 - PHPSTORM(xdebug, database, ftp, git, restful test)》
点击可以对比请求差异

我是觉得这个功能比之前那个http client好用的, 很大程度上可以不用其他的http client 来调试, 比如postman

他的接口测试看, 他的HTTP Requests Collection即可

php/js的单独文件执行

就和单个文件执行没什么差异, 有时候想输入的啥, 看结果, 这个就很方便

sql

直接输入sql执行, 好用

enjoy it !

    原文作者:优de良
    原文地址: https://segmentfault.com/a/1190000006850472
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞