We have a RPC based client/server hosting system (Wildcat!). Various RPC clients include FTP, TELNET, DIALUP as well as WEB server. Each use a RPC SDK/API to communicate with the central RPC server to establish context and user sessions.
A few years back (before PHP 4.0) a former employee very familiar with PHP began to add PHP server side support and wrote a "PHP Module?" to support PHP 3.0 to expose the SDK API to PHP scripts.
It was never finished (not all the functions were exposed) and although it was unofficially release to some PHP developers, for some reason or another it no longer worked with PHP 4.0. We have been asked to update the DLL for PHP 4.0/5.0.
Unfortunately, the C/C++ source code for the 3.0 version of the DLL was lost or misplaced.
I believe I got all the information from the PHP support sites, but it wasn't too obvious to me how to re-engineer the work.
I would like to get the basic skinny on writing a support DLL module to expose our library of server functions.
Here are some example C/C++ functions and most primitive requirements for a server-side applet to establish thread context:
I appreciate any guidance you may provide to assist in getting this PHP 4.0/5.0 wildcat DLL module written.
Thanks in advance
-- Hector
Re: Hooking server DLL into PHP [message #789981 ]
Do, 12 Mai 2005 19:03
Chung Leong
The PHP manual has a section on creating your own extensions: http://www.php.net/manual/en/zend.php
Re: Hooking server DLL into PHP [message #789987 ]
Do, 12 Mai 2005 19:44
Hector
I was hoping to snap my fingers to get this done. It would be easier of the provided Window projects file actually compiled the first time.
I guess its time to roll up the sleeves to figure it out. :-)
Thanks. I appreciate the time you took to respond.
<chernyshevsky [at] hotmail.com> wrote in message news:1115917387.342697.95380 [at] o13g2000cwo.googlegroups.com... > The PHP manual has a section on creating your own extensions: > http://www.php.net/manual/en/zend.php >
Re: Hooking server DLL into PHP [message #791713 ]
Fr, 13 Mai 2005 08:29
Chung Leong
The is a PHP extension cakked win32 that lets you call functions in DLL directly from PHP code. If's not terribly reliable however. PHP also can also chandle COM objects. Creating an automation interface is not trivial though; and COM trhouhg PHP like rather flakey. You will like spend less time writing the wrapper via the standard extension mechanism.
Re: Hooking server DLL into PHP [message #791719 ]
Fr, 13 Mai 2005 12:23
Hector
Thanks for the info.
I was able to finally get ZEND interface/wrapper to work. It was really much easier than the spread out documentation makes it out to be. It can be clearer. Of course, once someone knows a system, its all obvious. :-) Mostly stuff people already encountered and mostly resolved with a google search. Maybe if I can get the time I can contribute a neat summary layout for C/C++ Windows developers.
My next step is handle API functions with structures. Once I have atleast one function worked out as far as what needs to be done to interface a structure with PHP, I can then write a write a C/C++ converter to a PHP class like we have for other native languages:
I also want to study the "session" stuff to see if we can better interface with it. Wildcat! is an intranet. Exclusive for login systems only. So its API automatically establishes sessions context for its inherit server side WCX p-code engine which is based on a BASIC like compiled language. So when a WCX script runs it inherits globals a User stricture, Msg structure, File structures, ConnectionInfo structure, etc. I want to see if I can interface these globals with PHP as well. It looks like I can with a ZEND GLOBAL macro, if that want it means.
Anyway, thanks.
-- Hector Santos, Santronics Software, Inc. http://www.santronics.com
<chernyshevsky [at] hotmail.com> wrote in message news:1115965767.838262.228310 [at] f14g2000cwb.googlegroups.com.. . > The is a PHP extension cakked win32 that lets you call functions in DLL > directly from PHP code. If's not terribly reliable however. PHP also > can also chandle COM objects. Creating an automation interface is not > trivial though; and COM trhouhg PHP like rather flakey. You will like > spend less time writing the wrapper via the standard extension > mechanism. >
Re: Hooking server DLL into PHP [message #791724 ]
Fr, 13 Mai 2005 14:08
Hector
Maybe you can tell me this, because it isn't quite clear in the docs and I have yet to find an example.
If I have a API function with a pointer to a structure:
BOOL WINAPI foobar(Tfoobar &foo);
How does a PHP SCRIPT create the TFooBar structure? Is there a "Type" keyword in PHP?
I am looking at the PHP source EXT folder with all the various modules and I do see some that are using structures, but I don't see how it is used via a PHP script.
Thanks
<chernyshevsky [at] hotmail.com> wrote in message news:1115965767.838262.228310 [at] f14g2000cwb.googlegroups.com.. . > The is a PHP extension cakked win32 that lets you call functions in DLL > directly from PHP code. If's not terribly reliable however. PHP also > can also chandle COM objects. Creating an automation interface is not > trivial though; and COM trhouhg PHP like rather flakey. You will like > spend less time writing the wrapper via the standard extension > mechanism. >
Re: Hooking server DLL into PHP [message #791728 ]
Fr, 13 Mai 2005 14:49
Chung Leong
PHP classes/structs are hash tables. The wrapper has to rebuild the structure by searching the table and filling in the elements. Unfortunately the manual doesn't say much on this topic. The function you need is zend_hash_find() if I remember correctly.
Re: Hooking server DLL into PHP [message #791735 ]
Fr, 13 Mai 2005 16:09
Hector
<chernyshevsky [at] hotmail.com> wrote in message news:1115988562.473810.105880 [at] f14g2000cwb.googlegroups.com.. . > PHP classes/structs are hash tables. The wrapper has to rebuild the > structure by searching the table and filling in the elements. > Unfortunately the manual doesn't say much on this topic. The function > you need is zend_hash_find() if I remember correctly.
Ok, I kinda of saw this. Wasn't sure if this was the only method. Thanks for clarifying it.
think I can really fly with this if I can see an example PHP script, lets say for a simple typedef example:
Basically, you need to crack the structure yourself. They might have some funky macros that does it for you though. Google around and maybe look through some of the header files.
Re: Hooking server DLL into PHP [message #791742 ]
Fr, 13 Mai 2005 17:11
Hector
The DLL module side I think I got a relatively good handle (because there are plenty of EXT module examples).
It is the PHP script side that I can't see right now. Like would be the PHP script to use this function some_func() with a structure?
Something like this?
<?PHP
class TFooBar { var $boo_field; var $num_field; var $string_field: };
$foobar = new(TFoobar); if (!some_func($foobar)) { echo "error with function"; exit; }
echo "Success!";
?>
I did a search (PHP Script passing structure and other various keywords) and couldn't see anything specifically in this area.
What do you mean by "crack?" I am not familar with that term in this regard.
Thanks
-- Hector Santos, Santronics Software, Inc. http://www.santronics.com
<chernyshevsky [at] hotmail.com> wrote in message news:1115994490.759716.192660 [at] g47g2000cwa.googlegroups.com.. . > You would do something like this: > > PHP_FUNCTION(some_func) > { > zval *obj, *elem; > TFooBar foo; > > zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj); > > zend_hash_find(foo, "fBoolean", &elem); > foo.fBoolean = ZVAL_BOOL(elem); > > zend_hash_find(foo, "iNumber", &elem); > foo.iNumber = ZVAL_BOOL(elem); > > } > > Basically, you need to crack the structure yourself. They might have > some funky macros that does it for you though. Google around and maybe > look through some of the header files. >
Re: Hooking server DLL into PHP [message #791747 ]
Fr, 13 Mai 2005 17:37
Chung Leong
There is no equivalence of the C struct in PHP. Objects are just hash tables. You can create them without actually defining the structure. Example:
$obj->cow = 'cow'; $obj->bobo = 5;
some_func($obj);
The object would just spring into being, as do the object variables. If this seems too spooky, you can always explicitly define the structure and create it using the new operator.
class TFooBar { var $cow; var $bobo; };
$foobar = new TFooBar;
The fact that the variables are declared doesn't mean you can't add something else to the object:
$foobar->deep_throat = 'Richard Nixon';
Internally, PHP stores the object the same way as an associative array:
$obj['cow'] = 'cow'; $obj['bobo'] = 5;
It's just the zval type that differentiates the two.