about develop c/c++ extend

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
coolcc
Forum Newbie
Posts: 5
Joined: Tue Jan 05, 2010 1:56 am

about develop c/c++ extend

Post by coolcc »

we usually write the arithmetic in PHP.

for example an easy arithmetic in PHP easy.php

Code: Select all

<?php
for($i=1;$i<=10;$i++)
{
    echo $i."<br />";
}
 
if we write it in C++ easy.cpp

Code: Select all

#include <iostream>
int main()
{
 int i = 0;
 for(i=1;i<=10;i++)
 {
   std::cout << i << std::endl;
 }
 return 0;
 
}
 
I have a problem that use c/c++ develop the php's arithmetic extend.
if we compile the "easy.cpp" to "easy.dll"(windows) or "easy.so"(linux) ,and than let php invoke the "dll" or "so" cover for "easy.php".
which code is faster ? invoke the "dll,so" or only use php ?
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: about develop c/c++ extend

Post by JNettles »

That depends on if you're going to be compiling the DLL into PHP or simply calling it using the dl function to load it at runtime. If you add it as a PHP extension and enable it through your php.ini file (and the extension is doing all of the math work) then that route will probably be significantly quicker as its already compiled into byte code. If you load it manually using dl then I'm going to guess it will be a heavy load time, but thats just my best guess since I've never actually went that route.

In short, if you can load it as a PHP extension then go that route. Otherwise stick to the PHP math libraries (I'm guessing these are non-standard calculations that PHP doesn't already have built-in).
coolcc
Forum Newbie
Posts: 5
Joined: Tue Jan 05, 2010 1:56 am

Re: about develop c/c++ extend

Post by coolcc »

Thanks for your help . Now I know how to do . Thank you very much. Thank you.
michejohnson
Forum Newbie
Posts: 4
Joined: Wed Dec 30, 2009 2:46 am

Re: about develop c/c++ extend

Post by michejohnson »

Hello JNettles,
I am also facing the same problem but I could not solve it from
a week. You have given very useful and clear solution so that I
can solve my problem. Thank you so much for helping.
Post Reply