By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,408 Members | 1,624 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,408 IT Pros & Developers. It's quick & easy.

Hooking server DLL into PHP

P: n/a
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:

BOOL WINAPI wcConnect(const char *szServerName="");
BOOL WINAPI wcCreateContext();
BOOL WINAPI wcCreateContextByChallenge(const char *szChalllege);
BOOL WINAPI wcDeleteContext();

I'm not a PHP script programming expert, but I see a script like so:

<?PHP
// establish context

$challenge = getenv("WILDCATCONTEXT");
if (!wcCreateContextByChallenge($challenge)) {
echo "Error creating context";
end??
}

... use other API functions ....
wcDeleteContext();
?>

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

Jul 17 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
The PHP manual has a section on creating your own extensions:
http://www.php.net/manual/en/zend.php

Jul 17 '05 #2

P: n/a
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.
<ch***********@hotmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
The PHP manual has a section on creating your own extensions:
http://www.php.net/manual/en/zend.php


Jul 17 '05 #3

P: n/a
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.

Jul 17 '05 #4

P: n/a
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:

CPP2VB (visual basic
CPP2PAS (delphi pascal)
CPP2VFP (visual foxpro)
CPP2JAVA (java)
CPP2PHP (php)

etc.

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
<ch***********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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.


Jul 17 '05 #5

P: n/a
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

<ch***********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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.


Jul 17 '05 #6

P: n/a
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.

Jul 17 '05 #7

P: n/a

<ch***********@hotmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.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:

typedef struct _TFooBar {
BOOL fBoolean;
int iNumber;
char szString[256];
} TFooBar;

What is the PHP script for this? Whats the interface like?

Do I have to expose each field as a Function "Get/Put" like method?

--
Hector Santos, Santronics Software, Inc.
http://www.santronics.com

Jul 17 '05 #8

P: n/a
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.

Jul 17 '05 #9

P: n/a
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
<ch***********@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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.


Jul 17 '05 #10

P: n/a
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.

Jul 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.