Understanding the how to deal with pending events is an important part of programming with GTK. While not technically accurate (in any regards), it is useful to think of a PHP-GTK application as two threads or processes working together for one program. In one hand you have PHP running the program, on the other you have the GTK library running an idle loop to process its UI. If you hard lock PHP into a processing (for, while, foreach) loop GTK will be unable to process its updates until PHP finishes, and visa versa.

Here is an example where you might run into this issue. Lets say you have a directory full of files you need to read, and a window displaying a progress bar. These are two symptoms you might encounter:

  1. the appearance that your program has hardlocked and must be killed, and then at the last minute your progress bar jumps to 100%.
  2. your progress bar updates sporadically jumping large amounts instead of smoothly across.

… and both of these, generally, can be solved very easily. Most of the time just telling GTK to process events is enough to do it. And how do we do that?

Continue reading about GTK Pending Events…