Using C to calculate in a PHP application: is it worth it?

I have a PHP application where heavy computation is sometimes required (I look for operations recorded by users and do a lot of economic analysis over a long period of time).

I would like to improve the speed of these calculations, is it worth rewriting these calculations in C? (Among the faster languages here , C is the one I know the most).

I already decided to do this, but when I was looking for โ€œhow to do thisโ€, I found this question about stack overflow . Someone commented there: โ€œWhy not just write the whole site / page using PHP or C?โ€ and I know that I need more information.

+6
source share
1 answer

If you are really concerned about performance, measure first if the PHP (or other) implementation is fast enough. You may find out that there is no need to worry. If these are really difficult calculations (and it is likely that they will increase as your application develops), it would be advisable to run the calculations asynchronously in a separate server service. For example, your PHP interface might send a C / C ++ service that ultimately puts the results in a database. This requires a lot of additional logic, someone (the client) will have to interrogate regularly, but it scales well.

There are other things to consider than performance: if your math is complex and continues to grow, PHP may not be a good medium for formulating it. Again, perhaps a Java stack with a clear separation of interfaces and business logic might be best in terms of service.

0
source

Source: https://habr.com/ru/post/973881/


All Articles