Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C/C++ code in PHP without writing an extension

I read it's possible to use C/C++ code in PHP by writing an extension. Is there a simpler way, like wrapping magic or things like that (I must say, I heard the word, but don't know much about what a wrapper is).

like image 530
sameold Avatar asked Nov 06 '11 23:11

sameold


People also ask

Can you use C with PHP?

PHP will not run your C code, even though they have similar syntaxes. The PHP exec function will execute a command similar to how it is done in a shell or command prompt. You could exec gcc -o myc myc.

Can we use C++ in PHP?

The PHP-CPP library uses all the power offered by C++11 to convert the parameters and return values from your functions to/and from PHP. The function above is a native C++ function. With PHP-CPP you can export this function to PHP with only one single C++ method call.

What is a PHP extension?

php file extension refers to the name of a file with a PHP script or source code that has a ". PHP" extension at the end of it. It's similar to a Word file with a . doc file extension.


1 Answers

Compiling a php extension isn't very hard. There is a little API to learn just like C programs has the main function and how to pass variables to the main function.

like image 96
Micromega Avatar answered Sep 19 '22 03:09

Micromega