Jump to content

Recommended Posts

I need to perform some very large and processing-intensive math calculations. Speed is of the essence here, so I want to make that part run as native compiled object code, written in C/C++. PHP seems to be too slow.

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.

Thanks!
Link to comment
https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/
Share on other sites

[!--quoteo(post=369817:date=Apr 29 2006, 03:07 PM:name=KrisNz)--][div class=\'quotetop\']QUOTE(KrisNz @ Apr 29 2006, 03:07 PM) [snapback]369817[/snapback][/div][div class=\'quotemain\'][!--quotec--]
perhaps [a href=\"http://php.net/com\" target=\"_blank\"][b]this[/b][/a] is what you're after?
[/quote]
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.
No need to use .NET at all. COM will let you access dll's as com objects.

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.
  • 2 weeks later...
[!--quoteo(post=372066:date=May 8 2006, 02:09 AM:name=neylitalo)--][div class=\'quotetop\']QUOTE(neylitalo @ May 8 2006, 02:09 AM) [snapback]372066[/snapback][/div][div class=\'quotemain\'][!--quotec--]
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? :D
[/quote]
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.
  • 3 weeks later...
Haven't made much progress, this extension is pretty tough [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /]

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, [b]the Visual C++ 6 project file itself[/b] 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)

Thanks!
[!--quoteo(post=381465:date=Jun 9 2006, 01:34 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 9 2006, 01:34 AM) [snapback]381465[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Yeah... Id'e probably agree. I would think most php developers would be working in Linux. Windows isn't exactly a great developement environment.
[/quote]
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.


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.