Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make PHP and C/C++ interact with each other

Tags:

c++

c

php

I have the usual PHP and MYSQL server running but I want to perform some CPU intensive computations. Therefore I wish to run a C program to handle that part.

Is it possible to exchange data between a PHP and a C/C++ program on the server itself?

Regards PP

like image 804
Pranjal Avatar asked Sep 05 '25 03:09

Pranjal


2 Answers

It's possible and you have multiple ways to achieve that.

  • write an extension (as it was already suggested)
  • call your C program with 'exec()'
  • use Gearman
  • run C program as a service and communicate with it via pipe or a socket

From the above I would choose an extension or Gearman.

like image 152
Lukasz Kujawa Avatar answered Sep 07 '25 20:09

Lukasz Kujawa


Why not write a C++ program and then use popen to fetch the results when it is executed.

like image 45
Ed Heal Avatar answered Sep 07 '25 20:09

Ed Heal