Troubleshooting CGI programs
This topic lists common CGI program problems and solutions.
You can use the Work with Active Jobs (WRKACTJOB) command to check on the status of server jobs. To start Work with Active Jobs command, type the following in during a 5250 session on a command line:
WRKACTJOB SBS(QHTTPSVR) JOB(server_instance)
Where server_instance is the name of your HTTP Server instance.
When the server is not processing a request, the Work with Active Jobs display will show several server jobs. The first job is the manager job for the server instance. (Function PGM-QZHBMAIN). Server jobs showing PGM - QZSRLOG are logging jobs. Server jobs showing PGM - QZSRHTTP are primary jobs. (There will be 2 of these unless you specify HotBackup Off in your configuration.) Only one of these jobs will be actively handling requests. Jobs showing PGM -QZSRCGI are CGI jobs.
To find out if server jobs have ended abnormally, check the spooled files that contain the job logs (QPJOBLOG) for the user profile QTMHHTTP.
More CGI troubleshooting tips and hints can be found at the Troubleshooting your CGI program Web
page on the HTTP Server Web site.
The symptoms that are described in this section would be seen running a request to the server at a browser.
List of symptoms:
- Symptom: Connection abandoned, dropped, or no data sent
- Symptom: The system is not converting or handling special characters as expected
- Symptom: Error 500: Bad script request -- script '/qsys.lib/qsyscgi.lib/progname.pgm' not found or not executable
- Symptom: A browser request that runs a CGI program runs longer than expected. The browser keeps waiting for a response
- Symptom: A CGI written form is not cached in the browser
- Symptom: The configuration uses the CGIConvMode value of %%MIXED/MIXED%% and the input characters your CGI program receives are incorrect
Symptom: Connection abandoned, dropped, or no data sent
- No data written to stdout
- No “Content-type”, “Location”, or “Status” line
- No new line character after HTTP response header
- No data after HTTP response header.
Content-type: text/plain\n \n This data is returned to the client
- Issue the command ENDTCPSVR *HTTP HTTPSVR(server_instance)
- Issue the command STRTCPSVR *HTTP HTTPSVR(server_instance
'-minat 1 -maxat 1')Note: You also may need to change script_timeout and output_timeout to be larger. If you are stepping through your code, it may take too long and script_timeout or output_timeout may expire. This causes the server to terminate the job you are debugging.
Ending and starting the server ensures that only one worker job is running.
- Issue the command WRKACTJOB JOB(server_instance)
Look for the CGI jobs as described above.
Select option 10 to display the job log.
If your CGI program is single thread capable, message HTP2001 will be in the job log. If your CGI program is multithread capable, message HTP2002 will be in the job log.
Record the Number:, User:, and Job: values for your CGI program job.
Press F12.
Issue the command STRSRVJOB <Number/User/Job>.
- For the user CGI program, issue the command STRDBG <usercgilib/cgipgm>
If the program accesses a database file on the server, you must specify UPDPROD(*YES). See the help for the STRDBG command.
Note: You will need additional authority to troubleshoot the CGI program. For example, you will need authority to the QTMHHTTP user profile. - Set breakpoints in the program.
- On the browser, issue a URL that would run the CGI program.
- After the system issues an HTTP request on the browser, return
to the session that ran STRSRVJOB. It should
have stopped at a program breakpoint.
Ending and starting the server ensures that only one worker thread is running.
- Issue the command WRKACTJOB JOB(server_instance)
- When finished with debug, reset the server values:
- Issue the command ENDDBG
- Issue the command ENDSRVJOB
- Issue the command WRKACTJOB SBS(QHTTPSVR) JOB(server_instance)
- Issue the command STRTCPSVR *HTTP HTTPSVR(server_instance)
Symptom: The system is not converting or handling special characters as expected
There are two approaches to handling escape sequences:
- Convert the EBCDIC representation of the ASCII escape sequence to an EBCDIC escape sequence or use CGI input mode %%EBCDIC%%. This is necessary because the QtmhCvtDB API assumes that escape sequences represent EBCDIC code points, and the API converts them to the corresponding EBCDIC character. For example, %2C, which represents an ASCII comma, is converted to EBCDIC X'2C', which is not an EBCDIC comma.
- Convert the EBCDIC representation of the ASCII escape sequence to the EBCDIC equivalent character.
The following approach outlined in the first conversion technique listed above:
- Convert the “xx” in “%xx” to the corresponding EBCDIC character. In this case 0xF2C3 is converted to 0x2C.
- For the first approach, convert the EBCDIC character to the two-byte
form. Then you can reinsert the two bytes back into the input stream
in the same place they originally appeared. The 0x6B would be converted
to 0xF6C2, and the resultant escape sequence would be 0x6CF6C2. For
the second approach, leave the data in its EBCDIC form and replace
the original escape sequence (three characters) with the single character.
In this case, replace 0x6CF2C3 with 0x6B.Note: The CGI program should preserve an escape sequence that represents the character “%”.
- Call QtmhCvtDB to convert the input stream.Note: 7-bit ASCII CCSID 367 is standard on browsers.
Symptom: Error 500: Bad script request -- script '/qsys.lib/qsyscgi.lib/progname.pgm' not found or not executable
This message can appear for the following reasons:
- The script does not exist.
- There is a problem with the script, for example, a send error or function check.
- The user QTMHHTP1 does not have authority to run this program.
Symptom: A browser request that runs a CGI program runs longer than expected. The browser keeps waiting for a response
Symptom: A CGI written form is not cached in the browser
Using the back button on the browser results in a request to the server. The form contains no headers or meta tags telling the browser to request (not cache) the page.