te7 Posted December 15, 2014 Share Posted December 15, 2014 I have a PHP website with some simple functions. I want to add more functions that use intensive mathematical routines. I want to use a C++ dll to do this. Or I can also compile for *Nix if the necessary for portability. How would I load the .dll (Windows) or .so (*Nix) and then use the functions from it. Any help would be appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/293102-how-to-use-c-dll-with-php/ Share on other sites More sharing options...
requinix Posted December 15, 2014 Share Posted December 15, 2014 Write and compile a PHP extension that uses the DLL. But if the code isn't too much then you might as well ignore the DLL and put the code in the extension itself. Quote Link to comment https://forums.phpfreaks.com/topic/293102-how-to-use-c-dll-with-php/#findComment-1499606 Share on other sites More sharing options...
te7 Posted December 15, 2014 Author Share Posted December 15, 2014 (edited) How would you write and compile a PHP extension that uses the DLL? Does this also depend on what version of PHP the hosting site uses? I'm sort of a PHP newbie, although I'm proficient in other languages. About porting the code to PHP: how would the speed be for intensive mathematical operations? Is PHP designed for this? I guess I could try it to see how it goes. Edited December 15, 2014 by te7 Quote Link to comment https://forums.phpfreaks.com/topic/293102-how-to-use-c-dll-with-php/#findComment-1499607 Share on other sites More sharing options...
requinix Posted December 15, 2014 Share Posted December 15, 2014 How would you write and compile a PHP extension that uses the DLL?It starts by knowing C... Do you? For something as simple as math it won't be so bad but you do would need to learn about the PHP internals a bit. Does this also depend on what version of PHP the hosting site uses?Yes, to a point. But the main problem is that your hosting company is probably not going to let you load a PHP extension. Have you verified they're even using Windows? About porting the code to PHP: how would the speed be for intensive mathematical operations?Let me put it this way: if PHP's implementation is too slow then you shouldn't be using PHP at all. Is PHP designed for this?It's as "designed for this" as is, say, C. Exactly what is this math stuff? Quote Link to comment https://forums.phpfreaks.com/topic/293102-how-to-use-c-dll-with-php/#findComment-1499608 Share on other sites More sharing options...
te7 Posted December 15, 2014 Author Share Posted December 15, 2014 I have large integer arrays (multi-dimentional) that the DLLs to go through and remove duplicate items in the arrays. I have both a Visual Basic and a C# app that uses the C++ DLLs because putting the code inline with the apps makes the code WAY too slow (part of managed code performance issues). I could easily port the code in the DLLs to PHP if it wouldn't be a performance issue. The DLLs performance with Visual Basic and C# is very good. I just wanted to be able to add some buttons to my website to perform these calculations and output as displayed html files (new tab popup windows). Quote Link to comment https://forums.phpfreaks.com/topic/293102-how-to-use-c-dll-with-php/#findComment-1499610 Share on other sites More sharing options...
Frank_b Posted December 15, 2014 Share Posted December 15, 2014 (edited) With complex calculations PHP's automatic typecasting could be a problem. Also as far as i know PHP only supports up to 32 bit integers. There are a few opensource C(++) webserver's available on the net with documentation. If you run you own (virtual) private server it should be posible to run a secondary webserver on a different port. One example is https://code.google.com/p/mongoose/ Edited December 15, 2014 by Frank_b Quote Link to comment https://forums.phpfreaks.com/topic/293102-how-to-use-c-dll-with-php/#findComment-1499616 Share on other sites More sharing options...
te7 Posted December 15, 2014 Author Share Posted December 15, 2014 Thanks for the info. Quote Link to comment https://forums.phpfreaks.com/topic/293102-how-to-use-c-dll-with-php/#findComment-1499627 Share on other sites More sharing options...
requinix Posted December 15, 2014 Share Posted December 15, 2014 I have large integer arrays (multi-dimentional) that the DLLs to go through and remove duplicate items in the arrays.Depending where those integers come from, and whether you can/need to get them as strings, PHP already has ways to remove duplicates from arrays and it's entirely C code. Also as far as i know PHP only supports up to 32 bit integers.Most Linuxes have 64-bit PHP now. It's really only Windows which is stuck in 32-bit land. Quote Link to comment https://forums.phpfreaks.com/topic/293102-how-to-use-c-dll-with-php/#findComment-1499658 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.