Is it possible to write some C or C++ code and compile to binaries, then use those binaries with php? Is it also possible to write a php library using C and C++ ?
If
It is possible to write php extensions in C++ (but you must also write C facade). It isn't trivial, and I'd say, that if you ask instead of looking into PHP code, you're not so familiar with C and how PHP works inside, and due to it's bad documentation it is a bad idea for you to write library in C.
EDIT: there is a ... some basic tutorial on zend. http://devzone.zend.com/node/view/id/1021 , as I'm looking into it, maybe the documentation changed since my PHP times :)