PHP and Java applets are completely separate and there is no reason they would interact (and in fact, no means by which they could interact other than the applet making its own HTTP queries to the server). PHP is server-side code that outputs HTML and data to the client. Part of that HTML markup can include an object or embed tag to instruct the browser to load an applet. The applet then runs on the client side, not even the same machine that’s processing the PHP. Your solution of exiting the script will work fine, as will using an echo command in PHP to output the appropriate tags for the applet. On my pages, I use echo tags because I use the PHP to include some user-specific parameters to the applet tag. I suspect any difficulty you might have had generating the object/embed tag in PHP was just handling the quote marks.
This may be belaboring the point, but it’s important to realize that the code running on the server (PHP, JSP, Java servlet, ASP, CGI, plain HTML, whatever) has no effect or interaction with the applet running on the client. As long as the server-side code can output HTML, it can output the object or embed tag you want to use for the applet, and that’s all the browser running the applet cares about.