SCENARIO: I've used PHP extensively BUT am very new to extending it. However I've quickly got to get PHP 4.3.x talking to a certain C/C++ application that I am building for AI routines. I've also checked out a lot of "Building Custom PHP Extensions" tutorials, even the manual at http://www.php.net/manual/en/zend.php and liked them much. HOWEVER they deviate from what am looking for. Actually, what I see described @ http://www.zend.com/php/internals/extension-writing1.php appears like she's building certain functionality into PHP (I guess that's only half of how one can extend PHP) rather than get PHP to use functionality from an external program - much like interfacing it with MySQL or GD etc. I wish she was describing the latter method rather than the former. QUESTION: How then do I interface PHP with the C/C++ program without duplicating the AI effort into the PHP loadable module? Please advice
The thing is, what the author is describing is exactly what you need for interfacing with other applications like MySQL or GD... It really depends on how your application is set up to begin with. If your AI routines are in separate libraries, then it would be fairly simple to write a C-based PHP extension. You would just link to those libraries. If your AI application is scriptable, then you could probably just use PHP to write out the script and call the program with exec. However, if your AI application is a single file with everything built in to it, with the entire UI controlled by the mouse, then naturally this will be practically impossible to interact with without modifying the original program. It really depends on how the program you want to link to is set up, basically. So, we need to know more about the program you want to link with in the first place...