I think what you're trying to do is the following. You will need at least two PHP scripts. One for the HTML (we'll call it A.PHP), one for the embedded GIF (B.PHP).
A.PHP does the following-
embed html and php here
B.PHP does the following-
...generate image here...
Small footprint P2P web server for Windows,
File-sharing, PHP, wireless apps & more