/    Sign up×
Community /Pin to ProfileBookmark

How to use C++ dll with PHP

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.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Stephen_PhilbinDec 15.2014 — Is it a well known library, or something you've written yourself? If it's a well known library, then there may already be an option to just compile it in. On Linux you'd compile it in something like (if my memory serves me correctly) configure-script-dir#./configure --with-some-library=/path/to/library.so
configure-script-dir# make
configure-script-dir# make install
I don't know what the Windows equivalent would be, but it shouldn't be [i]too[/i] diferent.

If it's a custom made library then I don't really know. PHP is (to my knowlege) really just a framework that binds together various libraries. If the information you need is anywhere, I'd image it'd be here http://php.net/manual/en/internals2.structure.php
Copy linkTweet thisAlerts:
@NogDogDec 15.2014 — Or if it's something that can be called from the command line, you could use shell_exec(), perhaps?
Copy linkTweet thisAlerts:
@Stephen_PhilbinDec 15.2014 — Yeah, that's probably a much more sensible option. I'd imagine it'd be a heck of a lot less work than trying to build a PHP extension.

Just remember to thoroughly sanitise any user input that gets anywhere near exec.
×

Success!

Help @te7 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...