ext/scream functionality without ext/scream

There were some rumors recently about Gopals ext/scream. This extension disables the @ operators and therefore makes all errors visible. If you want to use the extension you have to build the extension and restart your PHP modules so that the extension is loaded.

But there is a more elegant to get the same behavior. Using DTrace and recent OpenSolaris 2009.06 we are able to use the php:::error probe to get all error messages. Unlike the PHP extension we do not need to restart our PHP. We are also able to just temporarily look into the errors of all running PHP processes. Here is the DTrace script:

#!/usr/sbin/dtrace -s

php*:::error {
printf("Error \"%s\" in file %s line %d\n", copyinstr(arg0), copyinstr(arg1), arg2);
}

This will display all errors that occur. There is also a php:::exception-thrown probe which can provide nearly the same data for exceptions instead of errors.

2 Comments

  1. Jan! says:

    Isn’t it easier to simply register your own error handler? When it gets called and |error_reporting() === 0|, it means the @ operator has been used.

    http://php.net/set_error_handler
    “It is important to remember that the standard PHP error handler is completely bypassed. error_reporting() settings will have no effect and your error handler will be called regardless – however you are still able to read the current value of error_reporting and act appropriately. Of particular note is that this value will be 0 if the statement that caused the error was prepended by the @ error-control operator.”

    • admin says:

      Yes, but it’s more work to do if you just want to have a short look on what happens. Also you have to add this for every PHP app running on the server, while the DTrace solution monitors all running PHP applications by default.