Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I print the entire program state in PHP?

PHP provides some impressive introspection facilities: get_defined_vars, get_defined_functions, get_defined_constants, debug_backtrace, and others. Essentially, these provide views of the entire program state: the stack and the heap. I wonder how complete a view of the program state one can get using these facilities.

The heap and all defined variables in scope can be modelled as a labelled directed graph. So is it possible, for example, to write something that will give me a Graphviz/DOT depiction of this? I'm imagining something similar to the diagrams in this article about 'How PHP manages variables', or to the diagrams in the PHP manual page on garbage collection.

like image 652
jameshfisher Avatar asked Dec 18 '13 16:12

jameshfisher


People also ask

How do I print a PHP script?

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.

Which is faster echo or print in PHP?

They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print .

How can I display the text with a PHP script?

PHP allows us to display the text in various formats using various inbuilt methods. Using echo command: The echo command can be used to display text, including numerical, strings and arrays.


2 Answers

Checkout xdebug plus the xdebug chrome extension. https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?hl=en

The extension can be used to enable profiling / debugging for php. You can link it with eclipse or any other ide that supports xdebug for debugging.

If you generate a profile you can put the results into kcachegrind or wincachegrind to get a map view of memory allocation, time spent in each function and other things.

https://www.youtube.com/watch?v=YHKFdfbcP8U

like image 120
Rich Wandell Avatar answered Sep 27 '22 20:09

Rich Wandell


If you generate a profile you can put the results into kcachegrind or wincachegrind to get a map view of memory allocation, time spent in each function and other things.

https://www.youtube.com/watch?v=YHKFdfbcP8U

like image 39
Ravi Chauhan Avatar answered Sep 27 '22 20:09

Ravi Chauhan