anroy Posted April 29, 2006 Share Posted April 29, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/ Share on other sites More sharing options...
KrisNz Posted April 29, 2006 Share Posted April 29, 2006 perhaps [a href=\"http://php.net/com\" target=\"_blank\"][b]this[/b][/a] is what you're after? Quote Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/#findComment-31898 Share on other sites More sharing options...
anroy Posted May 5, 2006 Author Share Posted May 5, 2006 [!--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 .dllI 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. Quote Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/#findComment-33503 Share on other sites More sharing options...
trq Posted May 7, 2006 Share Posted May 7, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/#findComment-34027 Share on other sites More sharing options...
neylitalo Posted May 7, 2006 Share Posted May 7, 2006 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 Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/#findComment-34086 Share on other sites More sharing options...
anroy Posted May 17, 2006 Author Share Posted May 17, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/#findComment-36657 Share on other sites More sharing options...
anroy Posted June 8, 2006 Author Share Posted June 8, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/#findComment-43043 Share on other sites More sharing options...
maxim Posted June 8, 2006 Share Posted June 8, 2006 maby they didnt make it with visual c++ Quote Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/#findComment-43243 Share on other sites More sharing options...
trq Posted June 8, 2006 Share Posted June 8, 2006 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 Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/#findComment-43256 Share on other sites More sharing options...
anroy Posted June 9, 2006 Author Share Posted June 9, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/8689-calling-native-libraries-from-php/#findComment-43472 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.