Sign in to follow this  
Prozak

Adding functionality to PHP

Recommended Posts

Prozak    898
PHP is a script language where you invoke functions. But someone has to write the C code for those functions. My questions is, can we make a DLL or something that plugs into PHP and add more callable functions, which would in turn invoke our own C code? This interests me because I would like to automate stuff like temperature sensing and the likes, and I already have the C code for that... Also, can you compile PHP? And what about protecting PHP code, so that if I make something I want to resell, I am somewhat protected against custumers just copy/pasting the code? (let's not discuss hardcore hackers here, just the casual user). Thanks for any tips guys [wink]

Share this post


Link to post
Share on other sites
SirLuthor    364
Prozak, AFAIK PHP is open source, thus, if you need extra functionality which is not included in the base distribution, you can hack it in yourself. It should not be all that difficult (presumably) to add the ability to call your own functions, or load an extra DLL and call functions from it. As for 'compiling PHP', again as far as I know, that is not possible. As far as protection goes, if you really feel like you need it (seeing as the casual user can't just view your code, all he sees is HTML and/or javascript) you oculd probably hack together an encryption/decryption for your PHP code, have it shoved between <? and >? tags, and have the PHP DLL decrypt it on the fly, seeing as IIRC all the server does when it encounters the PHP tags is send the data contained in them to the PHP DLL. At least, that is how I recall it goes.

Hope this helps

Share this post


Link to post
Share on other sites
Mattman    336
You can create DLL's that can be used in PHP. That's one way of making certain PHP functions available in Windows (e.g. all the mysql calls). I've never done it myself though, so I don't know what steps need to be taken to do this... good luck!

Share this post


Link to post
Share on other sites
Spoonbender    1258
Zend has a PHP compiler, as far as I know. I think it only compiles to some kind of bytecode, but not sure. At the very least, it would protect your code somewhat (while improving performance)

Share this post


Link to post
Share on other sites
markr    1692
You can create PHP extensions which register their own functions and/or classes which are usable from PHP. These are compiled into DLL files (Or .so files etc) (or built into PHP directly), and can be loaded from php.ini.

As far as compiling is concerned - you can't do this without some add-on to PHP, like the "Zend Accelerator", which also supports compiled PHP files.

Depending on the complexity of the API you intend to expose, you could consider using an external callable program (i.e. a standalone executable) instead of making a PHP extension - and call it from PHP with system(), popen() or similar. That might prove easier, and is more likely to work with different versions of PHP etc.

Mark

Share this post


Link to post
Share on other sites
Zahlman    1682
You might consider working with Python instead. There is pretty good support/documentation for interfacing it with C or C++ (in the C++ case there is Boost::Python, and also SWIG, but you may prefer to just expose a C-style interface and do things manually following the C guides), and it is bytecode-compiled (like Java). Also, it's similarly high-level but a lot cleaner ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this