<p>How do you debug <strong>PHP</strong> scripts?</p>

<p>I am aware of basic debugging such as using the Error Reporting. The breakpoint debugging in <strong>PHPEclipse</strong> is also quite useful.</p>

<p>What is the <strong>best</strong> (in terms of fast and easy) way to debug in phpStorm or any other IDE?</p>

[{'answer_id': 889, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 4, 'selected': False, 'text': '<p>I\'ve used the <a href="http://www.zend.com/products/studio/" rel="noreferrer">Zend Studio (5.5)</a>, together with <a href="http://www.zend.com/en/products/platform/" rel="noreferrer">Zend Platform</a>. That gives proper debugging, breakpoints/stepping over the code etc., although at a price.</p>\n'}, {'answer_id': 890, 'author': 'John Downey', 'author_id': 200, 'author_profile': 'https://Stackoverflow.com/users/200', 'pm_score': 8, 'selected': True, 'text': '<p>Try <a href="https://eclipse.org/pdt/" rel="noreferrer">Eclipse PDT</a> to setup an Eclipse environment that has debugging features like you mentioned. The ability to step into the code is a much better way to debug then the old method of var_dump and print at various points to see where your flow goes wrong. When all else fails though and all I have is SSH and vim I still <code>var_dump()</code>/<code>die()</code> to find where the code goes south.</p>\n'}, {'answer_id': 891, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 2, 'selected': False, 'text': '<p>print_r( debug_backtrace() );</p>\n\n<p>or something like that :-)</p>\n'}, {'answer_id': 1587, 'author': 'Christian Lescuyer', 'author_id': 341, 'author_profile': 'https://Stackoverflow.com/users/341', 'pm_score': 4, 'selected': False, 'text': '<p><a href="http://xdebug.org/" rel="noreferrer">Xdebug</a>, by Derick Rethans, is very good. I used it some time ago and found it was not so easy to install. Once you\'re done, you won\'t understand how you managed without it :-)</p>\n\n<p>There is a good article on <a href="http://devzone.zend.com/article/2803-introducing-xdebug" rel="noreferrer">Zend Developer Zone</a> (installing on Linux doesn\'t seem any easier) and even a <a href="https://addons.mozilla.org/fr/firefox/addon/3960" rel="noreferrer">Firefox plugin</a>, which I never used.</p>\n'}, {'answer_id': 1602, 'author': 'Teifion', 'author_id': 1384652, 'author_profile': 'https://Stackoverflow.com/users/1384652', 'pm_score': 4, 'selected': False, 'text': "<p>In all honesty, a combination of print and print_r() to print out the variables. I know that many prefer to use other more advanced methods but I find this the easiest to use.</p>\n\n<p>I will say that I didn't fully appreciate this until I did some Microprocessor programming at Uni and was not able to use even this.</p>\n"}, {'answer_id': 1758, 'author': 'Polsonby', 'author_id': 137, 'author_profile': 'https://Stackoverflow.com/users/137', 'pm_score': 0, 'selected': False, 'text': "<p>+1 for print_r(). Use it to dump out the contents of an object or variable. To make it more readable, do it with a pre tag so you don't need to view source. </p>\n\n<pre><code>echo '&lt;pre&gt;';\nprint_r($arrayOrObject);\n</code></pre>\n\n<p>Also var_dump($thing) - this is very useful to see the type of subthings</p>\n"}, {'answer_id': 2599, 'author': 'Pat', 'author_id': 238, 'author_profile': 'https://Stackoverflow.com/users/238', 'pm_score': 6, 'selected': False, 'text': '<p>You can use Firephp an add-on to firebug to debug php in the same environment as javascript.</p>\n\n<p>I also use <a href="http://xdebug.org/" rel="noreferrer">Xdebug</a> mentioned earlier for profiling php.</p>\n'}, {'answer_id': 3579, 'author': 'Eric Lamb', 'author_id': 538, 'author_profile': 'https://Stackoverflow.com/users/538', 'pm_score': 0, 'selected': False, 'text': '<p>Depending on the issue I like a combination of error_reporting(E_ALL) mixed with echo tests (to find the offending line/file the error happened in initally; you KNOW it\'s not always the line/file php tells you right?), IDE brace matching (to resolve "Parse error: syntax error, unexpected $end" issues), and print_r(); exit; dumps (real programmers view the source ;p). </p>\n\n<p>You also can\'t beat phpdebug (check sourceforge) with "memory_get_usage();" and "memory_get_peak_usage();" to find the problem areas.</p>\n'}, {'answer_id': 4172, 'author': 'jlleblanc', 'author_id': 586, 'author_profile': 'https://Stackoverflow.com/users/586', 'pm_score': 4, 'selected': False, 'text': '<p>1) I use print_r(). In TextMate, I have a snippet for \'pre\' which expands to this:</p>\n\n<pre><code>echo "&lt;pre&gt;";\nprint_r();\necho "&lt;/pre&gt;";\n</code></pre>\n\n<p>2) I use Xdebug, but haven\'t been able to get the GUI to work right on my Mac. It at least prints out a readable version of the stack trace.</p>\n'}, {'answer_id': 11956, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>In a production environment, I log relevant data to the server's error log with error_log().</p>\n"}, {'answer_id': 13817, 'author': 'Brendon-Van-Heyzen', 'author_id': 1425, 'author_profile': 'https://Stackoverflow.com/users/1425', 'pm_score': 1, 'selected': False, 'text': '<p>i use zend studio for eclipse with the built in debugger. Its still slow compared to debugging with eclipse pdt with xdebug. Hopefully they will fix those issues, the speed has improved over the recent releases but still stepping over things takes 2-3 seconds.\nThe zend firefox toolbar really makes things easy (debug next page, current page, etc). Also it provides a profiler that will benchmark your code and provide pie-charts, execution time, etc.</p>\n'}, {'answer_id': 22675, 'author': 'Karim', 'author_id': 2494, 'author_profile': 'https://Stackoverflow.com/users/2494', 'pm_score': 3, 'selected': False, 'text': "<p>For the really gritty problems that would be too time consuming to use print_r/echo to figure out I use my IDE's (PhpEd) debugging feature.  Unlike other IDEs I've used, PhpEd requires pretty much no setup.  the only reason I don't use it for any problems I encounter is that it's <em>painfully</em> slow.  I'm not sure that slowness is specific to PhpEd or any php debugger.  PhpEd is not free but I believe it uses one of the open-source debuggers (like XDebug previously mentioned) anyway.  The benefit with PhpEd, again, is that it requires no setup which I have found really pretty tedious in the past.</p>\n"}, {'answer_id': 22681, 'author': 'Ross', 'author_id': 2025, 'author_profile': 'https://Stackoverflow.com/users/2025', 'pm_score': 2, 'selected': False, 'text': '<p>Manual debugging is generally quicker for me - <code>var_dump()</code> and <code>debug_print_backtrace()</code> are all the tools you need to arm your logic with.</p>\n'}, {'answer_id': 22691, 'author': 'Julio César', 'author_id': 2148, 'author_profile': 'https://Stackoverflow.com/users/2148', 'pm_score': 5, 'selected': False, 'text': '<p><a href="http://www.xdebug.org/" rel="noreferrer">XDebug</a> is essential for development. I install it before any other extension. It gives you stack traces on any error and you can enable profiling easily.</p>\n\n<p>For a quick look at a data structure use <a href="http://www.php.net/manual/en/function.var-dump.php" rel="noreferrer"><code>var_dump()</code></a>. Don\'t use <code>print_r()</code> because you\'ll have to surround it with <code>&lt;pre&gt;</code> and it only prints one var at a time.</p>\n\n<pre><code>&lt;?php var_dump(__FILE__, __LINE__, $_REQUEST); ?&gt;\n</code></pre>\n\n<p>For a real debugging environment the best I\'ve found is <a href="http://www.activestate.com/Products/komodo_ide/index.mhtml" rel="noreferrer">Komodo IDE</a> but it costs $$.</p>\n'}, {'answer_id': 22695, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Komodo IDE works well with xdebug, even for the remore debugging. It needs minimum amount of configuration. All you need is a version of php that Komodo can use locally to step through the code on a breakpoint. If you have the script imported into komodo project, then you can set breakpoints with a mouse-click just how you would set it inside eclipse for debugging a java program.\nRemote debugging is obviously more tricky to get it to work correctly ( you might have to map the remote url with a php script in your workspace ) than a local debugging setup which is pretty easy to configure if you are on a MAC or a linux desktop.</p>\n'}, {'answer_id': 23359, 'author': 'Michael Luton', 'author_id': 2158, 'author_profile': 'https://Stackoverflow.com/users/2158', 'pm_score': 0, 'selected': False, 'text': '<p>The integrated debuggers where you can watch the values of variable change as you step through code are really cool. They do, however, require software setup on the server and a certain amount of configuration on the client. Both of which require periodic maintenance to keep in good working order.</p>\n\n<p>A print_r is easy to write and is guaranteed to work in any setup.</p>\n'}, {'answer_id': 28284, 'author': 'Ignacio', 'author_id': 3086, 'author_profile': 'https://Stackoverflow.com/users/3086', 'pm_score': 4, 'selected': False, 'text': '<p>I use Netbeans with XDebug. \nCheck it out at its website for docs on how to configure it.\n<a href="http://php.netbeans.org/" rel="noreferrer">http://php.netbeans.org/</a></p>\n'}, {'answer_id': 66572, 'author': 'djn', 'author_id': 9673, 'author_profile': 'https://Stackoverflow.com/users/9673', 'pm_score': 5, 'selected': False, 'text': '<p>Xdebug and the DBGp plugin for Notepad++ for heavy duty bug hunting, FirePHP for lightweight stuff. Quick and dirty? Nothing beats <a href="http://dbug.ospinto.com/" rel="noreferrer">dBug</a>.</p>\n'}, {'answer_id': 81725, 'author': 'Toby Allen', 'author_id': 6244, 'author_profile': 'https://Stackoverflow.com/users/6244', 'pm_score': 3, 'selected': False, 'text': '<p>PhpEdit has a built in debugger, but I usually end up using echo(); and print_r(); the old fashioned way!!</p>\n'}, {'answer_id': 89699, 'author': 'Nathan Strong', 'author_id': 9780, 'author_profile': 'https://Stackoverflow.com/users/9780', 'pm_score': 2, 'selected': False, 'text': '<p>Well, to some degree it depends on where things are going south. That\'s the first thing I try to isolate, and then I\'ll use echo/print_r() as necessary.</p>\n\n<p>NB: You guys know that you can pass true as a second argument to print_r() and it\'ll return the output instead of printing it? E.g.:</p>\n\n<pre><code>echo "&lt;pre&gt;".print_r($var, true)."&lt;/pre&gt;";\n</code></pre>\n'}, {'answer_id': 224920, 'author': 'Joshi Spawnbrood', 'author_id': 15392, 'author_profile': 'https://Stackoverflow.com/users/15392', 'pm_score': 0, 'selected': False, 'text': '<p>Usually I find create a custom log function able to save on file, store debug info, and eventually re-print on a common footer.</p>\n\n<p>You can also override common Exception class, so that this type of debugging is semi-automated.</p>\n'}, {'answer_id': 224986, 'author': 'Ken', 'author_id': 20074, 'author_profile': 'https://Stackoverflow.com/users/20074', 'pm_score': 3, 'selected': False, 'text': "<p>Output buffering is very useful if you don't want to mess up your output. I do this in a one-liner which I can comment/uncomment at will </p>\n\n<pre><code> ob_start();var_dump(); user_error(ob_get_contents()); ob_get_clean();\n</code></pre>\n"}, {'answer_id': 515128, 'author': 'monk.e.boy', 'author_id': 563932, 'author_profile': 'https://Stackoverflow.com/users/563932', 'pm_score': 4, 'selected': False, 'text': '<p>PhpEd is really good. You can step into/over/out of functions. You can run ad-hoc code, inspect variables, change variables. It is amazing.</p>\n'}, {'answer_id': 1058375, 'author': 'eisberg', 'author_id': 113154, 'author_profile': 'https://Stackoverflow.com/users/113154', 'pm_score': 5, 'selected': False, 'text': "<p>This is my little debug environment:</p>\n\n<pre><code>error_reporting(-1);\nassert_options(ASSERT_ACTIVE, 1);\nassert_options(ASSERT_WARNING, 0);\nassert_options(ASSERT_BAIL, 0);\nassert_options(ASSERT_QUIET_EVAL, 0);\nassert_options(ASSERT_CALLBACK, 'assert_callcack');\nset_error_handler('error_handler');\nset_exception_handler('exception_handler');\nregister_shutdown_function('shutdown_handler');\n\nfunction assert_callcack($file, $line, $message) {\n    throw new Customizable_Exception($message, null, $file, $line);\n}\n\nfunction error_handler($errno, $error, $file, $line, $vars) {\n    if ($errno === 0 || ($errno &amp; error_reporting()) === 0) {\n        return;\n    }\n\n    throw new Customizable_Exception($error, $errno, $file, $line);\n}\n\nfunction exception_handler(Exception $e) {\n    // Do what ever!\n    echo '&lt;pre&gt;', print_r($e, true), '&lt;/pre&gt;';\n    exit;\n}\n\nfunction shutdown_handler() {\n    try {\n        if (null !== $error = error_get_last()) {\n            throw new Customizable_Exception($error['message'], $error['type'], $error['file'], $error['line']);\n        }\n    } catch (Exception $e) {\n        exception_handler($e);\n    }\n}\n\nclass Customizable_Exception extends Exception {\n    public function __construct($message = null, $code = null, $file = null, $line = null) {\n        if ($code === null) {\n            parent::__construct($message);\n        } else {\n            parent::__construct($message, $code);\n        }\n        if ($file !== null) {\n            $this-&gt;file = $file;\n        }\n        if ($line !== null) {\n            $this-&gt;line = $line;\n        }\n    }\n}\n</code></pre>\n"}, {'answer_id': 2801537, 'author': 'Petr Peller', 'author_id': 190438, 'author_profile': 'https://Stackoverflow.com/users/190438', 'pm_score': 1, 'selected': False, 'text': '<p>The most of bugs can be found easily by simply <code>var_dump</code>ing some of key variables, but it obviously depends on what kind of application you develop.</p>\n\n<p>For a more complex algorithms the step/breakpoint/watch functions are very helpful (if not necessary)</p>\n'}, {'answer_id': 2801595, 'author': 'CafeHey', 'author_id': 269404, 'author_profile': 'https://Stackoverflow.com/users/269404', 'pm_score': 2, 'selected': False, 'text': "<p>I often use CakePHP when Rails isn't possible. To debug errors I usually find the <code>error.log</code> in the tmp folder and tail it in the terminal with the command...</p>\n\n<pre><code>tail -f app/tmp/logs/error.log\n</code></pre>\n\n<p>It give's you running dialog from cake of what is going on, which is pretty handy, if you want to output something to it mid code you can use.</p>\n\n<pre><code>$this-&gt;log('xxxx');\n</code></pre>\n\n<p>This can usually give you a good idea of what is going on/wrong.</p>\n"}, {'answer_id': 3209562, 'author': 'Jannie Theunissen', 'author_id': 96944, 'author_profile': 'https://Stackoverflow.com/users/96944', 'pm_score': 4, 'selected': False, 'text': '<p>I use Netbeans with XDebug and the <a href="http://www.elime.be/easyxdebug.htm" rel="noreferrer" title="Easy XDebug FireFox Add-on">Easy XDebug FireFox Add-on</a> </p>\n\n<p>The add-on is essential when you debug MVC projects, because the normal way XDebug runs in Netbeans is to register the dbug session via the url. With the add-on installed in FireFox, you would set your Netbeans project properties -> Run Configuratuion -> Advanced and select "Do Not Open Web Browser" You can now set your break points and start the debugging session with Ctrl-F5 as usual. Open FireFox and right-click the Add-on icon in the right bottom corner to start monitoring for breakpoints. When the code reaches the breakpoint it will stop and you can inspect your variable states and call-stack.</p>\n'}, {'answer_id': 10799401, 'author': 'Mufaddal', 'author_id': 1326539, 'author_profile': 'https://Stackoverflow.com/users/1326539', 'pm_score': 2, 'selected': False, 'text': '<p>Nusphere is also a good debugger for php\n<a href="http://www.nusphere.com/download.php.ide.htm" rel="nofollow">nusphere</a></p>\n'}, {'answer_id': 32886213, 'author': 'shekh danishuesn', 'author_id': 5291660, 'author_profile': 'https://Stackoverflow.com/users/5291660', 'pm_score': 2, 'selected': False, 'text': '<p>There are many PHP debugging techniques that can save you countless hours when coding. An effective but basic debugging technique is to simply turn on error reporting. Another slightly more advanced technique involves using print statements, which can help pinpoint more elusive bugs by displaying what is actually going onto the screen. PHPeclipse is an Eclipse plug-in that can highlight common syntax errors and can be used in conjunction with a debugger to set breakpoints.</p>\n\n<pre><code>display_errors = Off\nerror_reporting = E_ALL \ndisplay_errors = On\n</code></pre>\n\n<p>and also used</p>\n\n<pre><code>error_log();\nconsole_log();\n</code></pre>\n'}, {'answer_id': 36131176, 'author': 'kenorb', 'author_id': 55075, 'author_profile': 'https://Stackoverflow.com/users/55075', 'pm_score': 1, 'selected': False, 'text': '<h3><a href="http://phpdbg.com/" rel="nofollow noreferrer">PHP DBG</a></h3>\n\n<p>The Interactive Stepthrough PHP Debugger implemented as a SAPI module which can give give you complete control over the environment without impacting the functionality or performance of your code. It aims to be a lightweight, powerful, easy to use debugging platform for PHP 5.4+ and it\'s shipped out-of-box with PHP 5.6.</p>\n\n<p>Features includes:</p>\n\n<ul>\n<li>Stepthrough Debugging</li>\n<li>Flexible Breakpoints (Class Method, Function, File:Line, Address, Opcode)</li>\n<li>Easy Access to PHP with built-in eval()</li>\n<li>Easy Access to Currently Executing Code</li>\n<li>Userland API</li>\n<li>SAPI Agnostic - Easily Integrated</li>\n<li>PHP Configuration File Support</li>\n<li>JIT Super Globals - Set Your Own!!</li>\n<li>Optional readline Support - Comfortable Terminal Operation</li>\n<li>Remote Debugging Support - Bundled Java GUI</li>\n<li>Easy Operation</li>\n</ul>\n\n<p>See the screenshots:</p>\n\n<p><a href="https://i.stack.imgur.com/yFHuH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yFHuH.png" alt="PHP DBG - Stepthrough Debugging - screenshot"></a></p>\n\n<p><a href="https://i.stack.imgur.com/WVFoN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WVFoN.png" alt="PHP DBG - Stepthrough Debugging - screenshot"></a></p>\n\n<p>Home page: <a href="http://phpdbg.com/" rel="nofollow noreferrer">http://phpdbg.com/</a></p>\n\n<h3><a href="http://phperror.net/" rel="nofollow noreferrer">PHP Error</a> - Better error reporting for PHP</h3>\n\n<p>This is very easy to use library (actually a file) to debug your PHP scripts.</p>\n\n<p>The only thing that you need to do is to include one file as below (at the beginning on your code):</p>\n\n<pre><code>require(\'php_error.php\');\n\\php_error\\reportErrors();\n</code></pre>\n\n<p>Then all errors will give you info such as backtrace, code context, function arguments, server variables, etc. For example:</p>\n\n<p><a href="https://i.stack.imgur.com/csob7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/csob7.png" alt="PHP Error | Improve Error Reporting for PHP - screenshot of backtrace"></a>\n<a href="https://i.stack.imgur.com/ulpyZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ulpyZ.png" alt="PHP Error | Improve Error Reporting for PHP - screenshot of backtrace"></a>\n<a href="https://i.stack.imgur.com/ZiJwK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZiJwK.png" alt="PHP Error | Improve Error Reporting for PHP - screenshot of backtrace"></a></p>\n\n<p>Features include:</p>\n\n<ul>\n<li>trivial to use, it\'s just one file</li>\n<li>errors displayed in the browser for normal and ajaxy requests</li>\n<li>AJAX requests are paused, allowing you to automatically re-run them</li>\n<li>makes errors as strict as possible (encourages code quality, and tends to improve performance)</li>\n<li>code snippets across the whole stack trace</li>\n<li>provides more information (such as full function signatures)</li>\n<li>fixes some error messages which are just plain wrong</li>\n<li>syntax highlighting</li>\n<li>looks pretty!</li>\n<li>customization</li>\n<li>manually turn it on and off</li>\n<li>run specific sections without error reporting</li>\n<li>ignore files allowing you to avoid highlighting code in your stack trace</li>\n<li>application files; these are prioritized when an error strikes!</li>\n</ul>\n\n<p>Home page: <a href="http://phperror.net/" rel="nofollow noreferrer">http://phperror.net/</a></p>\n\n<p>GitHub: <a href="https://github.com/JosephLenton/PHP-Error" rel="nofollow noreferrer">https://github.com/JosephLenton/PHP-Error</a></p>\n\n<p>My fork (with extra fixes): <a href="https://github.com/kenorb-contrib/PHP-Error" rel="nofollow noreferrer">https://github.com/kenorb-contrib/PHP-Error</a></p>\n\n<h3><a href="https://en.wikipedia.org/wiki/DTrace" rel="nofollow noreferrer">DTrace</a></h3>\n\n<p>If your system supports <a href="http://php.net/manual/en/features.dtrace.php" rel="nofollow noreferrer">DTrace dynamic tracing</a> (installed by default on OS X) and your PHP is compiled with the DTrace probes enabled (<code>--enable-dtrace</code>) which should be by default, this command can help you to debug PHP script with no time:</p>\n\n<pre><code>sudo dtrace -qn \'php*:::function-entry { printf("%Y: PHP function-entry:\\t%s%s%s() in %s:%d\\n", walltimestamp, copyinstr(arg3), copyinstr(arg4), copyinstr(arg0), basename(copyinstr(arg1)), (int)arg2); }\'\n</code></pre>\n\n<p>So given the following alias has been added into your <em>rc</em> files (e.g. <code>~/.bashrc</code>, <code>~/.bash_aliases</code>):</p>\n\n<pre><code>alias trace-php=\'sudo dtrace -qn "php*:::function-entry { printf(\\"%Y: PHP function-entry:\\t%s%s%s() in %s:%d\\n\\", walltimestamp, copyinstr(arg3), copyinstr(arg4), copyinstr(arg0), basename(copyinstr(arg1)), (int)arg2); }"\'\n</code></pre>\n\n<p>you may trace your script with easy to remember alias: <code>trace-php</code>.</p>\n\n<p>Here is more advanced dtrace script, just save it into <code>dtruss-php.d</code>, make it executable (<code>chmod +x dtruss-php.d</code>) and run:</p>\n\n<pre><code>#!/usr/sbin/dtrace -Zs\n# See: https://github.com/kenorb/dtruss-lamp/blob/master/dtruss-php.d\n\n#pragma D option quiet\n\nphp*:::compile-file-entry\n{\n    printf("%Y: PHP compile-file-entry:\\t%s (%s)\\n", walltimestamp, basename(copyinstr(arg0)), copyinstr(arg1));\n}\n\nphp*:::compile-file-return\n{\n    printf("%Y: PHP compile-file-return:\\t%s (%s)\\n", walltimestamp, basename(copyinstr(arg0)), basename(copyinstr(arg1)));\n}\n\nphp*:::error\n{\n    printf("%Y: PHP error message:\\t%s in %s:%d\\n", walltimestamp, copyinstr(arg0), basename(copyinstr(arg1)), (int)arg2);\n}\n\nphp*:::exception-caught\n{\n    printf("%Y: PHP exception-caught:\\t%s\\n", walltimestamp, copyinstr(arg0));\n}\n\nphp*:::exception-thrown\n{\n    printf("%Y: PHP exception-thrown:\\t%s\\n", walltimestamp, copyinstr(arg0));\n}\n\nphp*:::execute-entry\n{\n    printf("%Y: PHP execute-entry:\\t%s:%d\\n", walltimestamp, basename(copyinstr(arg0)), (int)arg1);\n}\n\nphp*:::execute-return\n{\n    printf("%Y: PHP execute-return:\\t%s:%d\\n", walltimestamp, basename(copyinstr(arg0)), (int)arg1);\n}\n\nphp*:::function-entry\n{\n    printf("%Y: PHP function-entry:\\t%s%s%s() in %s:%d\\n", walltimestamp, copyinstr(arg3), copyinstr(arg4), copyinstr(arg0), basename(copyinstr(arg1)), (int)arg2);\n}\n\nphp*:::function-return\n{\n    printf("%Y: PHP function-return:\\t%s%s%s() in %s:%d\\n", walltimestamp, copyinstr(arg3), copyinstr(arg4), copyinstr(arg0), basename(copyinstr(arg1)), (int)arg2);\n}\n\nphp*:::request-shutdown\n{\n    printf("%Y: PHP request-shutdown:\\t%s at %s via %s\\n", walltimestamp, basename(copyinstr(arg0)), copyinstr(arg1), copyinstr(arg2));\n}\n\nphp*:::request-startup\n{\n    printf("%Y, PHP request-startup:\\t%s at %s via %s\\n", walltimestamp, basename(copyinstr(arg0)), copyinstr(arg1), copyinstr(arg2));\n}\n</code></pre>\n\n<p><sup>Home page: <a href="https://github.com/kenorb/dtruss-lamp" rel="nofollow noreferrer">dtruss-lamp</a> at GitHub</sup></p>\n\n<p>Here is simple usage:</p>\n\n<ol>\n<li>Run: <code>sudo dtruss-php.d</code>.</li>\n<li>On another terminal run: <code>php -r "phpinfo();"</code>.</li>\n</ol>\n\n<p>To test that, you can go to any docroot with <code>index.php</code> and run PHP builtin server by:</p>\n\n<pre><code>php -S localhost:8080\n</code></pre>\n\n<p>After that you can access the site at <a href="http://localhost:8080/" rel="nofollow noreferrer">http://localhost:8080/</a> (or choose whatever port is convenient for you). From there access some pages to see the trace output.</p>\n\n<p>Note: Dtrace is available on OS X by default, on Linux you probably need <a href="https://github.com/dtrace4linux/linux" rel="nofollow noreferrer">dtrace4linux</a> or check for some other <a href="https://stackoverflow.com/q/2059311/55075">alternatives</a>.</p>\n\n<p>See: <a href="http://php.net/manual/en/features.dtrace.dtrace.php" rel="nofollow noreferrer">Using PHP and DTrace</a> at php.net</p>\n\n<hr>\n\n<h3><a href="https://en.wikipedia.org/wiki/SystemTap" rel="nofollow noreferrer">SystemTap</a></h3>\n\n<p>Alternatively check for SystemTap tracing by installing SystemTap SDT development package (e.g. <code>yum install systemtap-sdt-devel</code>).</p>\n\n<p>Here is example script (<code>all_probes.stp</code>) for tracing all core PHP static probe points throughout the duration of a running PHP script with SystemTap:</p>\n\n<pre><code>probe process("sapi/cli/php").provider("php").mark("compile__file__entry") {\n    printf("Probe compile__file__entry\\n");\n    printf("  compile_file %s\\n", user_string($arg1));\n    printf("  compile_file_translated %s\\n", user_string($arg2));\n}\nprobe process("sapi/cli/php").provider("php").mark("compile__file__return") {\n    printf("Probe compile__file__return\\n");\n    printf("  compile_file %s\\n", user_string($arg1));\n    printf("  compile_file_translated %s\\n", user_string($arg2));\n}\nprobe process("sapi/cli/php").provider("php").mark("error") {\n    printf("Probe error\\n");\n    printf("  errormsg %s\\n", user_string($arg1));\n    printf("  request_file %s\\n", user_string($arg2));\n    printf("  lineno %d\\n", $arg3);\n}\nprobe process("sapi/cli/php").provider("php").mark("exception__caught") {\n    printf("Probe exception__caught\\n");\n    printf("  classname %s\\n", user_string($arg1));\n}\nprobe process("sapi/cli/php").provider("php").mark("exception__thrown") {\n    printf("Probe exception__thrown\\n");\n    printf("  classname %s\\n", user_string($arg1));\n}\nprobe process("sapi/cli/php").provider("php").mark("execute__entry") {\n    printf("Probe execute__entry\\n");\n    printf("  request_file %s\\n", user_string($arg1));\n    printf("  lineno %d\\n", $arg2);\n}\nprobe process("sapi/cli/php").provider("php").mark("execute__return") {\n    printf("Probe execute__return\\n");\n    printf("  request_file %s\\n", user_string($arg1));\n    printf("  lineno %d\\n", $arg2);\n}\nprobe process("sapi/cli/php").provider("php").mark("function__entry") {\n    printf("Probe function__entry\\n");\n    printf("  function_name %s\\n", user_string($arg1));\n    printf("  request_file %s\\n", user_string($arg2));\n    printf("  lineno %d\\n", $arg3);\n    printf("  classname %s\\n", user_string($arg4));\n    printf("  scope %s\\n", user_string($arg5));\n}\nprobe process("sapi/cli/php").provider("php").mark("function__return") {\n    printf("Probe function__return: %s\\n", user_string($arg1));\n    printf(" function_name %s\\n", user_string($arg1));\n    printf("  request_file %s\\n", user_string($arg2));\n    printf("  lineno %d\\n", $arg3);\n    printf("  classname %s\\n", user_string($arg4));\n    printf("  scope %s\\n", user_string($arg5));\n}\nprobe process("sapi/cli/php").provider("php").mark("request__shutdown") {\n    printf("Probe request__shutdown\\n");\n    printf("  file %s\\n", user_string($arg1));\n    printf("  request_uri %s\\n", user_string($arg2));\n    printf("  request_method %s\\n", user_string($arg3));\n}\nprobe process("sapi/cli/php").provider("php").mark("request__startup") {\n    printf("Probe request__startup\\n");\n    printf("  file %s\\n", user_string($arg1));\n    printf("  request_uri %s\\n", user_string($arg2));\n    printf("  request_method %s\\n", user_string($arg3));\n}\n</code></pre>\n\n<p>Usage:</p>\n\n<pre><code>stap -c \'sapi/cli/php test.php\' all_probes.stp\n</code></pre>\n\n<p>See: <a href="http://php.net/manual/en/features.dtrace.systemtap.php" rel="nofollow noreferrer">Using SystemTap with PHP DTrace Static Probes</a> at php.net</p>\n'}]
['https://Stackoverflow.com/questions/888', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/131/']