Few weeks ago I had to use iDealer PHP library from C++. I did that and now the code has been tested and is working fine.
I had embedded Python before, so I knew what I had to do: initialize the PHP interpreter, create some variables, execute PHP code, read some PHP variables and shutdown the PHP interpreter. The first and the last step will be executed only once for whole server lifetime (performance considerations) while steps 2-4 will be executed for every request. To keep it simple, I will use global PHP variables and global symbol table known as EG(symbol_table) in C code and $GLOBALS in PHP code. To keep it even more simple, I will use only string PHP variables and will create a correct type ( array for example) in PHP code.
I can’t assure that everything written below is 100% correct, since PHP documentation was really poor, especially compared to Python. I found a part of solutions in Zend source code, so there might be a better and cleaner solutions. I also spent some time using gdb (The GNU Debugger) and valgrind and chasing bugs.
Continue reading “Embedding the PHP Interpreter”