Dtrace support for PHP
Dtrace is one of the coolest things in Solaris 10, adding great observability to applications. A Dtrace provider for PHP that adds probes to function entry and exit points has long been available. I finally got around to integrating this with the php in Cool Stack.
Bryan Cantrill has some excellent examples of how to use dtrace to trace through your php code, down to the system libraries and kernel (if you want to go that far !) .
Instructions for installing the php dtrace extension
1. Download the shared library for the extension :
2. Install the extension :
# bunzip2 dtrace.so.<arch>.bz2
# cp dtrace.so.<arch> /opt/coolstack/php5/lib/php/extensions/no-debug*/dtrace.so
3. Enable the dtrace extension :
Edit your php.ini (default is in /opt/coolstack/php5/lib/php.ini) and add the line :
extension="dtrace.so"
4. Check if the extension has been correctly loaded by executing a sample php script that takes a long time to run (you can use Bryan's blastoff.php to do this).
#/opt/coolstack# dtrace -l |grep php
39131 php16088 dtrace.so php_dtrace_execute function-entry
39132 php16088 dtrace.so php_dtrace_execute_internal function-entry
39133 php16088 dtrace.so php_dtrace_execute function-return
39134 php16088 dtrace.so php_dtrace_execute_internal function-return
#
5. You should now be able to use the dtrace provider whenever you want using dtrace scripts. The dtrace provider will work with mod_php if you're running Apache or if you're running php stand-alone. Here is a sample command that will show which functions are called :
# dtrace -n function-entry'{printf("called %s() in %s at line %d\n", \
copyinstr(arg0), copyinstr(arg1), arg2)}' -q
Please feel free to contribute additional dtrace scripts.
Shanti

Looks very cool!
Posted by Vitório Sassi on May 23, 2008 at 10:55 AM PDT #
hello,
i have problems with dtrace and php in os2008.11. Could you help me?
dtrace: error on enabled probe ID 57 (ID 5917: php26172:dtrace.so:php_dtrace_execute_internal:function-entry): invalid address (0xfceeb38b) in predicate at DIF offset 64
with:
php*:::function-entry
/arg0 != NULL && copyinstr(arg0) == ""/
{
printf("%d -> %-30s\n", pid, copyinstr(arg1));
}
php*:::function-return
/arg0 != NULL && copyinstr(arg0) == ""/
{
printf("%d <- %-30s\n", pid, copyinstr(arg1));
}
could you help me? A. Leventhal suggested me to contact you
Posted by gerard on January 09, 2009 at 10:15 PM PST #
Please use the Web Stack forum for support. It's at http://forums.sun.com/forum.jspa?forumID=980
And when you do, please state which version you're running on what platform.
Posted by Shanti on January 10, 2009 at 09:34 PM PST #