Jump to content

How to use C++ dll with PHP


te7

Recommended Posts

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.

 

Link to comment
Share on other sites

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 by te7
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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 by Frank_b
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.