采用C在PHP应用程序的计算:值得吗? [英] Using C for calculation in PHP application: is it worth it?
问题描述
我在需要重,有时计算一个PHP应用程序(我搜索了用户的操作记录,使许多经济分析在很长一段时间)。
I have a PHP application where sometimes heavy calculations are needed (I search for operations recorded by the users and make lots of economics analysis in long periods of time).
我想,以提高这些计算的速度,是值得重写用C这些计算部分? (其中更快的语言这里,C是一个我所知道的最)。
I'd like to improve the speed of these calculations, is it worth it to rewrite these calculations parts in C? (Among the faster languages here, C is the one I know the most).
我已经决定这样做,但是当我在寻找如何去做我发现的这个堆栈溢出问题。这里有人评论为什么不使用PHP或C 3 的只写整个网站/网页,我知道我需要额外的信息。
I had already decided doing this, but when I was looking for "how to do it" I found this Stack Overflow question. There someone commented "Why not just write the whole site/page using either PHP or C?" and I know I need extra info.
推荐答案
如果你真的担心的表现,测量第一个如果一个PHP(或其他方式)的实现是不够快。也许你会发现,没有必要担心。如果真的是重计算(并没有为你的应用程序的发展,他们将在越来越复杂的机会),它可能是值得在一个单独的后端服务异步运行的计算。比如你的PHP前端可以派遣到C / C ++的服务,最终的结果放置在数据库中。这需要很多额外的逻辑,有人(客户端)将不得不定期轮询,而是很好地扩展。
If you are really worried about performance, measure first if a PHP (or other) implementation is fast enough. Possibly you will find out that there is no need to worry. If it is really heavy calculations (and there is a chance they will grow in complexity as your application evolves), it could be worth to run the calculations asynchronously in a separate backend service. For example your PHP frontend could dispatch to a C/C++ service, which eventually places results in a database. This requires lots of extra logic, somebody (the client) will have to poll regularly, but scales nicely.
有比性能考虑的其他要点:如果你的数学的复杂而不断增加,PHP可能不是一个好的环境来制定的。话又说回来,也许与前端和业务逻辑清晰的分离基于Java的堆可能只是从一个维修点会更好。
There is other points to be considered than performance: if your math is complex and keeps growing, PHP may not be a good environment to formulate it. Then again, maybe a Java-based stack with a clear separation of frontend and business logic could be better just from a maintenance point of view.
这篇关于采用C在PHP应用程序的计算:值得吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!