Page 1 of 1

about develop c/c++ extend

Posted: Tue Jan 05, 2010 2:30 am
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 ?

Re: about develop c/c++ extend

Posted: Tue Jan 05, 2010 9:52 am
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).

Re: about develop c/c++ extend

Posted: Tue Jan 05, 2010 7:51 pm
by coolcc
Thanks for your help . Now I know how to do . Thank you very much. Thank you.

Re: about develop c/c++ extend

Posted: Sun Jan 10, 2010 12:29 am
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.