PHPStorm tips
2015-06-19 13:30
801 查看
phpstorm对于使用PHP开发web的人员来说,是一个非常不错的编辑开发IDE,以前用过sublime,但是相比于storm,sublime在浏览legacy代码,类代码编辑方面明显要逊色不少。
project->setting->Autoscroll to source、from source选中即可实现sublime一样单点就打开文件浏览的工作模式
上述设置无法保存,如果需要保存,则需要安装Autoscroll Save plugin
alt+home - 弹出当前目录以供操作
alt+insert - 目录context时, 在选中的目录中弹出创建...对话框
alt+insert - 文件内容context时,弹出创建construct,phpdoc等对话框,这时如果alit+enter则会提示initialize class 的fields
ctrl+w - 持续选择括号,方括号,tag内容,不断扩展, 非常好用!!!在sublime中必须通过扩展plugin来实现的
ctrl+d - 选择光标所在词,持续向下选择next occurence
ctrl+shitf+d -取消当前选择到的occurence
ctrl+shift+o - 浏览查找global symbol
alt+左键 - 多光标设置
shift+c -跳到代码code start的地方
shift+x -跳到代码code end的地方
alt+V - vertical split into two display window
alt+C - close active editor window
ctrl+E - recent files,可以快速在浏览过的文件中切换
ctrl+shift+E -recently changed files,列出最近修改过的文件
shift+enter -直接到下一行
/** + enter -为下面的代码加注释doc
ctrl+R -浏览类的成员,再次ctrl+R列出包含继承过来的成员
shift +s - toggle status bar
live template - 在自己的代码窗口中选中希望重用的代码,ctrl+shift+p, search live template, 选择save as live template即可使用
Mark changed file: file >> settings >> Editor >> Editor Tabs. Check Mark modified tabs with asterisk Click ok
phpStorm的auto save功能有时比较烦人,但是又没有好的方法来关闭,比较可行的方式是首先打开修改后mark为*的功能,随后可以在local history中选择变更
Settings / Appearance & Behavior / System Settings / Save file on frame deactivation: unchecked
Settings / Appearance & Behavior / System Settings / Save files automatically if...: unchecked
Settings / Editor / General / Editor tabs / Mark modified tabs with asterisk :checked
alt+ H: local history
dependency injection自动添加成员变量到
php --ini :列出本机php所使用的ini文件
http -S: 列出appache所使用conf文件
https://confluence.jetbrains.com/display/PhpStorm/Remote+debugging+in+PhpStorm+via+SSH+tunnel https://confluence.jetbrains.com/display/PhpStorm/Working+with+Remote+PHP+Interpreters+in+PhpStorm https://confluence.jetbrains.com/display/PhpStorm/Working+with+Advanced+Vagrant+features+in+PhpStorm
下面的资源是适用于laravel的Live templates
https://github.com/koomai/phpstorm-laravel-live-templates
debugging PHP with phpstorm
http://blog.jetbrains.com/phpstorm/2013/07/webinar-recording-debugging-php-with-phpstorm/ https://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm
1. 安装bookmark https://www.jetbrains.com/phpstorm/marklets/
2. Start Listening for PHP Debug Connections in PHPSTORM以便开始侦听debug请求
2.a: project->settings(ctrl+alt+s)->deployment增加一个描述如何deploy你的server的profile,配置sftp信息,配置path mapping(IDE to remote server)
关于path mapping,这篇文章有很详细的描述: http://blog.jetbrains.com/webide/2011/03/configure-php-debugging-in-phpstorm-2-0/
2.b: project->settings(ctrl+alt+s)->PHP->Servers选择上面的profile
3.可选在phpstorm中选择stop at the first line:在php代码第一行就暂停
3.在phpstorm中增加breakpoint
4.增加一个debug configuration,以方便在PHPStorm中直接快速执行debug命令
4.a运行run->debug xxx将启动一个默认浏览器,并且传递http://homestead.app:8000/?XDEBUG_SESSION_START=17769参数给homestead server,由xdebug捕捉到并且方向连接到PHPSTORM监听的调试端口9000,如果首次调试,则需要再PHPSTORM中点击接受调试请求,启动调试双向连接
4.b如果在bookmarklet安装的情况下,可以直接在浏览器中点击start debug this page按钮,浏览器就可以向phpstorm的debug监听接口发起请求
但是注意如果我们在file->settings->php->debug配置选项中勾选ignore external connections through unregistered server configuations,那么由于我们的homestead住在防火墙后面(使用8000端口),在 4.a模式下我们向homestead.app:8000端口通过get参数发起debug引擎启动请求,而随后homestead的web server又反向向phpstorm请求调试连接(注意这个回来的server_host参数是homestead.app:80端口!!!!)时,server host是不一样的,因此在上述debug配置选项的情况下,PHPStorm是会忽略debug连接请求的!!(9000端口)。
相反,如果我们没有勾选上面的选项,则phpstorm会提示我们是否接受来自homestead.app:80服务器来的调试请求,一旦我们接受,我们的phpstorm中就将增加了另外一个php server,而我们须要在这个server中配置path mapping,否则将可能无法hit breakpoint!(即便是通过xdebug_break()主动断点是工作的!),在debug界面会一直报file path is not mapped to any file path on server的错误(其原因就是无注册的server相匹配)。
IDE正常中断点的前提是当IDE侦听调试连接时,在php程序中的xdeubg_break()能够主动断掉!
5.reload这个page
5.a为了验证debug环境是否已经ok,可以通过在Php代码中人为增加一条xdebug代码: xdebug_break(); 随后浏览器访问服务器运行该代码,那么就应该触发IDE的breakpoint!!
有时你在php配置使能xdebug功能时,可能找不到相应的php.ini配置文件,方法是php --ini,这个命令就会列出系统的php到底使用的是哪一个php.ini文件
6.点击start debug将由browser初始化一个debug session并且向phpstorm发起请求
xdebug.ini中 remote_host = 192.168.56.1 这条可以由xdebug.remote_connect_back = 1来替代,增加一条 xdebug.idekey = "PHPSTORM", 这个信息是phpstorm中所需要的(在需要支持多个调试session时由debug proxy所需要)
随后重启vagrant中的web服务: sudo service php5-fpm restart
http://www.sitepoint.com/install-xdebug-phpstorm-vagrant/
如果在debug过程中,浏览器60s就会timeout,可以在/etc/nginx/nginx.conf中增加fastcgi_read_timeout 3600s;另外一个参数:
fastcgi_read_timeout 3600s;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/home/vagrant/Code"
随后执行sudo service php5-fpm restart即可。这时一旦执行任何一个url,则会在/home/vagrant/Code目录下生成相应的文件,这个文件在phpstorm的tools->analyze profiler file中分析,或者你也可以使用QCachegrind(windows),KCachegrind来做专业分析
http://sourceforge.net/projects/wincachegrind/ 分析器
xdebug.collect_params = 4 (最全的信息)
xdebug.collect_return = 1
xdebug.trace_format = 2 (2为html, 0为一般可读,1为机读)
xdebug_start_trace() xdebug_stop_trace()
function trace文件分析工具:
https://github.com/beberlei/xdebug-trace-gui
一旦配置完成后,后续在IDE中创建新的PHP Class时,IDE自动添加符合PSR-4规范的namespace!
https://www.youtube.com/watch?v=LUTolQw8K9A https://www.jetbrains.com/phpstorm/documentation/phpstorm-video-tutorials.jsp#10 http://stackoverflow.com/questions/15339165/cannot-debug-with-phpstorm-vagrant-xdebug https://confluence.jetbrains.com/display/PhpStorm/Remote+debugging+in+PhpStorm+via+SSH+tunnel
project->setting->Autoscroll to source、from source选中即可实现sublime一样单点就打开文件浏览的工作模式
上述设置无法保存,如果需要保存,则需要安装Autoscroll Save plugin
alt+home - 弹出当前目录以供操作
alt+insert - 目录context时, 在选中的目录中弹出创建...对话框
alt+insert - 文件内容context时,弹出创建construct,phpdoc等对话框,这时如果alit+enter则会提示initialize class 的fields
ctrl+w - 持续选择括号,方括号,tag内容,不断扩展, 非常好用!!!在sublime中必须通过扩展plugin来实现的
ctrl+d - 选择光标所在词,持续向下选择next occurence
ctrl+shitf+d -取消当前选择到的occurence
ctrl+shift+o - 浏览查找global symbol
alt+左键 - 多光标设置
shift+c -跳到代码code start的地方
shift+x -跳到代码code end的地方
alt+V - vertical split into two display window
alt+C - close active editor window
ctrl+E - recent files,可以快速在浏览过的文件中切换
ctrl+shift+E -recently changed files,列出最近修改过的文件
shift+enter -直接到下一行
/** + enter -为下面的代码加注释doc
ctrl+R -浏览类的成员,再次ctrl+R列出包含继承过来的成员
shift +s - toggle status bar
live template - 在自己的代码窗口中选中希望重用的代码,ctrl+shift+p, search live template, 选择save as live template即可使用
Mark changed file: file >> settings >> Editor >> Editor Tabs. Check Mark modified tabs with asterisk Click ok
phpStorm的auto save功能有时比较烦人,但是又没有好的方法来关闭,比较可行的方式是首先打开修改后mark为*的功能,随后可以在local history中选择变更
Settings / Appearance & Behavior / System Settings / Save file on frame deactivation: unchecked
Settings / Appearance & Behavior / System Settings / Save files automatically if...: unchecked
Settings / Editor / General / Editor tabs / Mark modified tabs with asterisk :checked
alt+ H: local history
dependency injection自动添加成员变量到
php --ini :列出本机php所使用的ini文件
http -S: 列出appache所使用conf文件
[root@AY130628135803343949Z]# httpd -S httpd: Could not reliably determine the server's fully qualified domain name, using 10.160.37.203 for ServerName VirtualHost configuration: 127.0.0.1:10083 is a NameVirtualHost default server localhost (/etc/httpd/conf.d/zendserver_gui.conf:6) port 10083 namevhost localhost (/etc/httpd/conf.d/zendserver_gui.conf:6) wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost port 80 namevhost www.xxxx.cn (/usr/local/zend/etc/sites.d/vhost_xxx.conf:1) Syntax OK
https://confluence.jetbrains.com/display/PhpStorm/Remote+debugging+in+PhpStorm+via+SSH+tunnel https://confluence.jetbrains.com/display/PhpStorm/Working+with+Remote+PHP+Interpreters+in+PhpStorm https://confluence.jetbrains.com/display/PhpStorm/Working+with+Advanced+Vagrant+features+in+PhpStorm
下面的资源是适用于laravel的Live templates
https://github.com/koomai/phpstorm-laravel-live-templates
debugging PHP with phpstorm
http://blog.jetbrains.com/phpstorm/2013/07/webinar-recording-debugging-php-with-phpstorm/ https://confluence.jetbrains.com/display/PhpStorm/Zero-configuration+Web+Application+Debugging+with+Xdebug+and+PhpStorm
Homestead+phpstorm remote debugging配置要点
远程调试的一般知识1. 安装bookmark https://www.jetbrains.com/phpstorm/marklets/
2. Start Listening for PHP Debug Connections in PHPSTORM以便开始侦听debug请求
2.a: project->settings(ctrl+alt+s)->deployment增加一个描述如何deploy你的server的profile,配置sftp信息,配置path mapping(IDE to remote server)
关于path mapping,这篇文章有很详细的描述: http://blog.jetbrains.com/webide/2011/03/configure-php-debugging-in-phpstorm-2-0/
2.b: project->settings(ctrl+alt+s)->PHP->Servers选择上面的profile
3.可选在phpstorm中选择stop at the first line:在php代码第一行就暂停
3.在phpstorm中增加breakpoint
4.增加一个debug configuration,以方便在PHPStorm中直接快速执行debug命令
4.a运行run->debug xxx将启动一个默认浏览器,并且传递http://homestead.app:8000/?XDEBUG_SESSION_START=17769参数给homestead server,由xdebug捕捉到并且方向连接到PHPSTORM监听的调试端口9000,如果首次调试,则需要再PHPSTORM中点击接受调试请求,启动调试双向连接
4.b如果在bookmarklet安装的情况下,可以直接在浏览器中点击start debug this page按钮,浏览器就可以向phpstorm的debug监听接口发起请求
但是注意如果我们在file->settings->php->debug配置选项中勾选ignore external connections through unregistered server configuations,那么由于我们的homestead住在防火墙后面(使用8000端口),在 4.a模式下我们向homestead.app:8000端口通过get参数发起debug引擎启动请求,而随后homestead的web server又反向向phpstorm请求调试连接(注意这个回来的server_host参数是homestead.app:80端口!!!!)时,server host是不一样的,因此在上述debug配置选项的情况下,PHPStorm是会忽略debug连接请求的!!(9000端口)。
相反,如果我们没有勾选上面的选项,则phpstorm会提示我们是否接受来自homestead.app:80服务器来的调试请求,一旦我们接受,我们的phpstorm中就将增加了另外一个php server,而我们须要在这个server中配置path mapping,否则将可能无法hit breakpoint!(即便是通过xdebug_break()主动断点是工作的!),在debug界面会一直报file path is not mapped to any file path on server的错误(其原因就是无注册的server相匹配)。
IDE正常中断点的前提是当IDE侦听调试连接时,在php程序中的xdeubg_break()能够主动断掉!
5.reload这个page
5.a为了验证debug环境是否已经ok,可以通过在Php代码中人为增加一条xdebug代码: xdebug_break(); 随后浏览器访问服务器运行该代码,那么就应该触发IDE的breakpoint!!
有时你在php配置使能xdebug功能时,可能找不到相应的php.ini配置文件,方法是php --ini,这个命令就会列出系统的php到底使用的是哪一个php.ini文件
6.点击start debug将由browser初始化一个debug session并且向phpstorm发起请求
xdebug.ini中 remote_host = 192.168.56.1 这条可以由xdebug.remote_connect_back = 1来替代,增加一条 xdebug.idekey = "PHPSTORM", 这个信息是phpstorm中所需要的(在需要支持多个调试session时由debug proxy所需要)
随后重启vagrant中的web服务: sudo service php5-fpm restart
http://www.sitepoint.com/install-xdebug-phpstorm-vagrant/
如果在debug过程中,浏览器60s就会timeout,可以在/etc/nginx/nginx.conf中增加fastcgi_read_timeout 3600s;另外一个参数:
fastcgi_read_timeout 3600s;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
如何使用profiler功能?
PHPStorm本身并不具备profiler功能,它主要完成对xdebug输出的profiler文件做分析。如何打开profiler功能呢?在php.ini文件中增加两行(一般在xdebug.ini中定义):xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/home/vagrant/Code"
随后执行sudo service php5-fpm restart即可。这时一旦执行任何一个url,则会在/home/vagrant/Code目录下生成相应的文件,这个文件在phpstorm的tools->analyze profiler file中分析,或者你也可以使用QCachegrind(windows),KCachegrind来做专业分析
http://sourceforge.net/projects/wincachegrind/ 分析器
execution trace(function trace)
如果你是项目的新加入者,对于系统是如何工作的没有清晰地了解,希望通过研究系统整个运作流程,那么使用xdebug的execution trace功能非常有帮助xdebug.collect_params = 4 (最全的信息)
xdebug.collect_return = 1
xdebug.trace_format = 2 (2为html, 0为一般可读,1为机读)
xdebug_start_trace() xdebug_stop_trace()
function trace文件分析工具:
https://github.com/beberlei/xdebug-trace-gui
Category | Setting | Values | Description | |
---|---|---|---|---|
Log file | xdebug.trace_output_dir | |||
xdebug.trace_output_name | ||||
xdebug.trace_options | 1 = append to trace file if it exists. 0 (default) = overwrite | |||
Select data per call | xdebug.collect_params | Non-zero = collect parameters passed to functions 0 = None. 1 = Type and number of elements (f.e. string(6), array(8)). 2 = Type and number of elements, with a tool tip for the full information 3 = Full variable contents (with limits set by xdebug.var_display_max_children, xdebug.var_display_max_data and xdebug.var_display_max_depth.) 4 = Full variable contents and variable name. | ||
xdebug.collect_return | 1 = write return values to trace file. Default 0 | |||
xdebug.collect_vars | 1 = analyze variables used in scope (slow). | |||
xdebug.collect_assignments | 1 = include variable assignments in execution traces | |||
Format | xdebug.trace_format | 0 = human readable indented format. time index, memory usage, memory delta (xdebug.show_mem_delta=1), level, function name, function parameters (xdebug.collect_params=1), filename and line number. 1 = computer readable format with different record type for enter stack frame and exit. See docs for fields. File line 2 says "File format: 2", which seems incorrect 2 = HTML format | ||
xdebug.show_mem_delta | 1 = show mem delta for each call | |||
Behavior | xdebug.auto_trace | 1 = enable trace just before script runs. Includes the auto_prepend_file | ||
xdebug.trace_enable_trigger | 1 = trigger trace using XDEBUG_TRACE GET/POST parameter, or set cookie XDEBUG_TRACE. To prevent Xdebug generating trace files for every request, set xdebug.auto_trace to 0. (Could not get this to work. This setting doesn't seem to be used in the XDebug source code.) Doh! See: [xdebug-general] Re: Is trace_enable_trigger defunct? Not implemented in Xdebug 2.1.2! | |||
Limits | xdebug.var_display_max_depth | Max levels of array elements and object properties that are displayed in trace output. Default 3. | ||
xdebug.var_display_max_data | Max string length for output of variables. Default 512. | |||
xdebug.var_display_max_children | Max number of array children and object properties that are displayed in trace output. Default 128 | |||
Functions to call in the PHP subject code
Category | Function | Description |
---|---|---|
ini_set() | Sets the value of a configuration option. I.e., substitute or override for settings in php.ini file. http://www.php.net/manual/en/function.ini-set.php | |
void xdebug_start_trace( string trace_file_path [, integer options] ) | Start tracing at this line of code. Trace file path is absolute, or relative to cwd. If no path given (empty string? No arg?) then xdebug uses setting xdebug.trace_output_dir. options is a bitmap: XDEBUG_TRACE_APPEND: 1 = append, 0 = overwrite XDEBUG_TRACE_COMPUTERIZED: 2 = Act as though xdebug.trace_format=1 (more elaborate format, but less human readable). 0 = Simpler format XDEBUG_TRACE_HTML: 4 = Output HTML table. 0 = output ordinary text | |
void xdebug_stop_trace() | Stop tracing and close output file. | |
string xdebug_get_tracefile_name() | Get name of output file. Useful in conjunction with xdebug.auto_trace, apparently. | |
Data display functions | Are these relevant? Where does their output go? | |
xdebug_var_dump() | ||
xdebug.show_local_vars |
auto namespacing
在编写PHP类代码过程中,如果使用了namespace,那么每次新创建类文件时需要指定namespace,同时为了使用composer的autoload功能,你又必须遵循PSR-4的目录布置及命名规范,这一点是比较繁琐的。PhpStorm可以解决这个问题,具体配置方式如下图:一旦配置完成后,后续在IDE中创建新的PHP Class时,IDE自动添加符合PSR-4规范的namespace!
https://www.youtube.com/watch?v=LUTolQw8K9A https://www.jetbrains.com/phpstorm/documentation/phpstorm-video-tutorials.jsp#10 http://stackoverflow.com/questions/15339165/cannot-debug-with-phpstorm-vagrant-xdebug https://confluence.jetbrains.com/display/PhpStorm/Remote+debugging+in+PhpStorm+via+SSH+tunnel
相关文章推荐
- PHP隐藏控件作用
- php JSON数据格式化方法
- php yii 出现Undefined index: Cid
- php session 阻塞 过期不自动清除session文件
- JS学习笔记(三):HTML通过ajax请求获取并显示php中的内容
- 预定义变量 - PHP手册笔记
- 引用 - PHP手册笔记
- 异常处理 - PHP手册笔记
- 命名空间 - PHP手册笔记
- 类与对象 - PHP手册笔记
- 函数 - PHP手册笔记
- PHP学习之[第07讲]PHP5.4 文件操作函数 之 图片计数器的实例
- 流程控制 - PHP手册笔记
- PHP自动生成表单代码分享
- 运算符 - PHP手册笔记
- PHP实现中文圆形印章特效
- PHP学习之[第06讲]数组、多维数组和数组函数
- Cannot modify header information - headers already sent by (output started at D:\PHP\xampp\htdocs\
- PHP 常用的header头部定义汇总
- PHP实现获取中英文首字母