Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you display php output into phpstorm's console?

Once a debugger (xdebug) is enabled in phpstorm, you can then run your php script (without debugging) from within phpstorm.

How do you view the output of the script in phpstorms console?

I want to see php's output before it gets read by the browser - basically what you would see if you clicked "view source" in the browser.

Here is a video of a jetbrains dev. doing this (2mins:05sec into video) - he just doesnt explain HOW to configure phpstorm to do it.

like image 306
Michael Coleman Avatar asked Jul 17 '14 10:07

Michael Coleman


People also ask

How do I print a PHP console?

The echo command is used in PHP to print any value to the HTML document. Use <script> tag inside echo command to print to the console.

How do I open the console in PhpStorm?

Open the Terminal tool window From the main menu, select View | Tool Windows | Terminal or press Alt+F12 .


2 Answers

Currently there is no such option in PhpStorm: to show web server buffer (what was sent to the browser) when debugging web page (note: this should work ONLY when debugging).

Such option did exist for a very short period about 4 years ago (separate Script Output tab in the debugger tool window: http://youtrack.jetbrains.com/issue/WI-2826 ).. but had quite a few issues and it was removed until properly implemented.

http://youtrack.jetbrains.com/issue/WI-18214 --> http://youtrack.jetbrains.com/issue/WI-4466


On that video, especially around 2:05 as you have suggested, ordinary CLI script is executed (Run/Debug Configuration of PHP Script type is used) and therefore ALL such output can be easily caught (standard std output).

With CLI scipt it's easy -- IDE is the parent here (he one who initiated script execution) so std output can easily be collected. If you execute your web page script in CLI environment, you will get your HTML in normal console output.

With web page it works differently (the whole process): script output is first sent to the web server (parent) which in turn sends it to the browser. Since IDE does not directly participate in script execution, such interception can only happen during debugging where debugger can send a copy of collected script output back to IDE.

like image 142
LazyOne Avatar answered Nov 04 '22 16:11

LazyOne


Most web frameworks buffer the output before sending the results to the webserver. To view the contents of this buffer, first insert a breakpoint at the desired location, then when the breakpoint is reached, then goto the Debug=>Console tab and execute the ob_get_contents() function. PHP's output buffering supported nested levels, so keep this in mind when choosing your breakpoint. Obviously if the CMS/framework doesn't use output buffering then this method doesn't apply.

like image 34
ttk Avatar answered Nov 04 '22 17:11

ttk