Calling native libraries from PHP
Posted 29 April 2006 - 04:08 AM
I want to call this C/C++ module from a PHP program running on Apache.
I want to do this for both Linux and Windows.
On the Windows side, I can write a DLL (Dynamically-Linked Library). Can you call a DLL from PHP? If so can you pass parameters to it, and get a return value? (The parameters and return values will, in my case, be lengthy complicated arrays. I guess this complicates things further, right? LOL )
As for the Linux side (where I am an newbie), is there anything akin to DLLs? If so what are they called? Can they be called from PHP at runtime?
Any advice is appreciated, no matter how partial or indirect.
Posted 05 May 2006 - 07:17 AM
perhaps [a href=\"http://php.net/com\" target=\"_blank\"]this[/a] is what you're after?
Thanks for the reply, but no, I am looking for something more straightforward, like how to call a simple .dll
I don't have the time to learn .NET and COM. Or is that the only option?
I am also looking to do the same thing on a Linux server. So I will need the Windows and Linux solutions to be as similar as possible so I would rather stay at a fairly low level and not abstract things too far from the metal.
I think the libraries on Linux are .so files? I have never programmed on Linux before. But C is common to both platform, and I just want to do math calculations, not any platform-dependent stuff, so I think I should be able to use the same source code, except perhaps for the entry point to the module.
Posted 07 May 2006 - 02:18 PM
Anyway... more to the point. Seems to me, if your going to be doing this in C anyway, your best bet might just be to build an extension for php. You could then either dynamically load the extension using [a href=\"http://php.net/dl\" target=\"_blank\"]dl[/a]() or rebuild php with the extension built in.
Posted 07 May 2006 - 05:09 PM
Posted 17 May 2006 - 04:28 PM
Since you just want to do math calculations, can't you use the [a href=\"http://www.php.net/manual/en/ref.math.php\" target=\"_blank\"]PHP math library[/a]? Or am I under-estimating the complexity of your calculations?
It is running in PHP at the moment but it is slow. As I wrote in my original post I want to speed it up.
Not rocket science in terms of complexity but just a very large number of multiplications and squaring. Looping through hundreds of thousands of these, will possibly increase to millions.
Posted 08 June 2006 - 02:10 AM
I am looking for some sample code to help me to write the .dll for Windows.
I have found various information on the web on writing PHP extensions but very little that is focused on Windows. Here is one, however it was written a few years ago and uses PHP 4.
[a href=\"http://www.devnewz.com/2002/0909.html\" target=\"_blank\"]http://www.devnewz.com/2002/0909.html[/a]
I would actually prefer if the sample code and, more importantly, the Visual C++ 6 project file itself were available. Project settings are always fraught with difficulties. It is not as if I could not figure it out eventually, the problem is that right now I literally have almost no time. And I would definitely prefer something using PHP 5!
Does anyone know of such a sample anywhere on the web? I realize this may be a long shot but it would help immensely if there is such a thing out there.
(By the way the PHP source code has extension sources in the ext folder, but no Visual C++ project file)
Posted 08 June 2006 - 04:34 PM
Posted 09 June 2006 - 01:43 AM
Yeah... Id'e probably agree. I would think most php developers would be working in Linux. Windows isn't exactly a great developement environment.
Actually I am going to be developing the exact same thing in Linux soon.
It will be my first time developing anything in Linux (have just started using it). It looks like there will be a huge learning curve but many developers say it is more enjoyable.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users