TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: matrix multiplication within PHP?

3 点作者 dxjones大约 16 年前
I am implementing a PHP-based web site that includes a simple recommender system. The key numerical calculation is a matrix multiplication. I am worried that doing this in PHP might be painfully slow. Does anyone else have experience doing numerical computations in PHP? I looked at writing my own PHP extension ( http://www.tuxradar.com/practicalphp/20/0/0 ) to implement matrix computations in C, ... but then it struck me someone else must have already encountered and solved this problem.<p>Any recommendations?

3 条评论

frisco大约 16 年前
From my experience, numerical algorithms at all complicated in PHP tend to lead to major suckage. We use Thrift (<a href="http://incubator.apache.org/thrift/" rel="nofollow">http://incubator.apache.org/thrift/</a>) to send the task to a daemon written in something more reasonable, most often either Python or C depending on required intensity. Works beautifully, few problems. Also, this lets you run the task asynchronously, so you can still return the page in N ms and then load the results on a lag: responsivity means a huge amount to users. Nothing's worse than the script dying from memory limits or timeouts and having the user get nothing (and PHP doesn't do threading).
评论 #575623 未加载
notaddicted大约 16 年前
If I were doing this, first I would profile the code. It is hard to know if it is significant or not.
评论 #576304 未加载
c00kie大约 16 年前
If it turns out to really be slow and you want to/have to stick with PHP, you could speed it up with the Strassen algorithm: <a href="http://en.wikipedia.org/wiki/Strassen_algorithm" rel="nofollow">http://en.wikipedia.org/wiki/Strassen_algorithm</a>