This article tells how to debug a PHP CLI script running on an IBM i, using Studio running on your personal computer.
Zend Server 7 for IBM i, running on any supported version of IBM i.
Zend Studio 12
Another post describing how to debug a PHP CLI script running on Linux can be found here:
This article is written with the assumption that remote debugging is already working well for you, that you can remotely debug IBM i scripts from Studio, and that you have been able to successfully debug an IBM i script running in your browser using the Studio toolbar. This just tells about the specific steps for PHP CLI.
To begin, please make sure Zend Studio is up and running on your computer. Studio needs to be active to receive the request to debug the script.
To debug the CLI script, run it in PASE. Please go to a 5250 command line and enter this command:
This brings up the PASE shell.
To run some command in the PASE shell, you type the command, one or more spaces, and an argument list. This is the format:
some_command some_argument another_argument
To run a PHP CLI script on IBM i, this is the command:
The argument list is the script to be run. If the script takes arguments, those additional arguments also are in the argument list, but to keep things simple, let's just run a script that takes no arguments. For example, we might have a very simple script named hello.php in directory /www/zendsvr6/htdocs/support. Then the argument would be:
So, to run this script using PHP CLI, we could run this command:
This would run the hello.php script, and the output from the script would appear in the PASE shell. Here is how this looks in the shell:
> /usr/local/zendsvr6/bin/php-cli /www/zendsvr6/htdocs/support/hello.php
To debug the script, we need to set an environment variable before running the command. This is done at the beginning of the same line where the command gets run. To set the variable, type the variable name, an equal sign, and some string, then one or more spaces, then the command, then one or more spaces, then the argument list. This is the format:
SOME_VARIABLE='some value' some_command some_argument another_argument
The variable we need to set to debug the CLI script is QUERY_STRING. The value for QUERY_STRING includes the ip address for your local computer running Studio, and the port Studio is using to listen for debug requests. That port will be 10137, unless you changed it in the settings. This is the format:
The ip address for the PC used in this example is 192.168.17.4, and the port is the default 10137, so the phrase to set the QUERY_STRING environment variable is this:
Adding that to the command to run our simple cli script gives this:
So we type all of that in to the PASE shell, and then press enter. The command moves up into the area where running commands go, but there is no output:
Now we switch over to Studio (remember, Studio has to be up and running on your computer). The script is open in Studio and is halted at the first line. Now we can set break points, run one line, run to the next break point, inspect variables, and do all the stuff we do with the debugger. After we finish debugging the script and allow it to run to completion, we return to PASE, and can see the script output there: