C​reating a Debug Log with the PHP Toolkit for IBM i

PHP on IBM iOne of my favorite features of the PHP Toolkit for IBM i is its ability to generate a detailed debug log. The log includes connection information, program call options, parameters in and out, and performance timing. When we receive questions about the toolkit as part of our SmartSupport, a debug log helps resolve the question quickly.

Why use the PHP Toolkit? It can call commands, RPG, COBOL, and CL programs, flexibly and fast. The debug log can make troubleshooting easier than with other methods that don’t have a log, such as stored procedures.

Two ways to enable and configure the debug log

1. Global configuration using toolkit.ini

The simplest way is to enable the debug log globally for all your PHP applications.

In the toolkit.ini file, which Seiden PHP+ stores by default at /QOpenSys/pkgs/lib/php/ToolkitApi/toolkit.ini, set debug=true, then run your script again. This will create /QOpenSys/var/tkit_debug.log or whatever path is given for debugLogFile.

The toolkit.ini section related to the debug log can look like this:

2. More flexible configuration in each PHP script

To enable logging for certain calls only, or for separate log paths per script, you can configure the debug log in your PHP code.

Assuming $conn is your toolkit connection object from your getInstance() function, add the line:

$conn->setOptions(array('debug'=>true, 'debugLogFile' =>'/any-path/tkit_debug.log'));

with the log file path you want to use. With Seiden PHP+, omitting the debugLogFile value will make the log default to this path:

/QOpenSys/var/tkit_debug.log

Permissions to create and write to the log file

However you enable the debug log, make sure your web server user profile (QTMHHTTP by default) has write permissions to the log file, or to the directory the log is in (if the log is not created yet.) Examples:

  • CHGAUT OBJ('/QOpenSys/var/tkit_debug.log') USER(QTMHHTTP) DTAAUT(*RW)
  • CHGAUT OBJ('/QOpenSys/var') USER(QTMHHTTP) DTAAUT(*WX) OBJAUT(*NONE) SUBTREE(*ALL) SYMLNK(*NO)

Check out our open source documentation library for more PHP tutorials. Better yet, join our Developer SmartSupport community to benefit from personal mentoring and on-demand answers to all your IBM i development questions.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.