Adding functionality to PHP

Started by
4 comments, last by Zahlman 18 years, 11 months ago
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]
Advertisement
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 &#106avascript) 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
Free speech for the living, dead men tell no tales,Your laughing finger will never point again...Omerta!Sing for me now!
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!
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)
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
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 ;)

This topic is closed to new replies.

Advertisement