I have a lot of mathematical calculations in my PHP script, which can be quite slow at times. I\'m wondering if it\'s possible to pass data from PHP to C++, do the calculati
php function system() would do the work. Just pass compiled c++ file to the system() and get the returned result.
You could always compile your code using Facebooks HipHop.
It will transform your php into C++ and then compile that to machine code using g++.
https://github.com/facebook/hiphop-php/wiki/
https://github.com/facebook/hiphop-php/wiki/Running-HipHop
I've never personally used it on a real project but I've heard great things.
To give another alternative, one that actually might even help you a great deal if you have to do multiple calculations at once that could run in parallel is to use Gearman.
Gearman will take care of the talking to C++ and you could run multiple calculations all at the same time. Gearman itself is simply a component that allows you to talk to it as a task server and you write workers that connect to it to execute the actual work. This also allows you to scale up, say you have something large to calculate, you could fire up 20 AWS EC2 instances and run the workers on there for the heavy lifting, then shut them down after it's done.
For best performance if it's straight forward and parallel execution is not needed, I would use Crashworks approach 100%, or you could mix the two.
Yes it can be done:
PHP can run commands on the server.
The process is different for both WINDOWS and LINUX systems
For windows check these links
exec Function
link for background processes in windows
For Linux:
system Function
Running a process in background
Well i tried to use this process and succeed a little.
And one more thing you can grab the results too
Create an executable in C++. Use proc_code to pass data to/from that executable andd get that executable to do the calculations.