When you say screen shot, do you mean text-mode screen dump (i.e. a text file containing what is visible on the tty), or a graphical screenshot?
Is the PHP interpreter running in the terminal, or as a separate process (e.g. run by a web server?)
Assuming the answer to those question are "graphical" and "separate process", here's how to do it:
The traditional X-Windows way to save a screenshot of a window is with the
xwd program. Usually this program has the user select the window to dump using the mouse, but you can also specify it using the X window ID.
The overview of the process is therefore like this:
- Get the window-id of the terminal
- Call xwd for the window-id
- Post process dump file (e.g. translate to a format like png)
The trick will be getting the window-id...