Execute script on remote host and obtain variables on localhost
This has numerous problems with it, one of which is the race condition. Imagine two clients connect to the server at the same time. Which client's tmp.json wins? The other client gets bad data.

Another problem with the current way of doing things is that you start a new PHP interpreter for each request. So, it's not as lightweight as you're envisioning.

You really need to develop a protocol for sending the two data streams back, and then implement that protocol. A temporary file should not be necessary.