Ah, I think I have figured it out! The PHP temporary file has the form /tmp/phpblahblah whereas calibre assumes that the filename has the structure name.format so I guess I have to rename this temporary file to have .mobi extension for ebook-meta to work. I have reproduced the "everything=Unknown" problem by running ebook-meta on a file without .mobi extension, so I am pretty sure this is the cause of the problem. I'll try it in the real PHP scenario now...
UPDATE: Yes, it works now!
UPDATE: No, on some books it still breaks with this error:
No protocol specified
: cannot connect to X server :0
This is the case when it outputs (when executed as a normal user) the message "loaded the Generic plugin". So, this "Generic plugin" seems to be an X application and wants to connect to X server. Very strange... Any ideas? (I'll try setting DISPLAY but really this is wrong --- standalone text-based utilities are NOT supposed to require X to run).
UPDATE: the solution is to unset DISPLAY before executing ebook-meta.
All these tricks should really be documented somewhere...