如何在没有客户端交互的情况下处理数据库处理服务器端?
我有一个正在尝试规划的系统,但我不知道如何攻击它。
该系统将从(希望是许多)客户端获取输入并将其存储在数据库(MySQL)中。这很简单(PHP 脚本)。
我不确定的部分是:在一定的时间间隔(每五分钟),服务器需要处理客户端在过去五分钟内提交的数据,并推送结果(基本上是输入的平均值) )到当前连接的客户端(我想我有一个计划......使用 Socket.IO 的“推送”部分),同时让这些结果可用于将来的请求(对于带有以下内容的动态 XML 文件来说也不难PHP)。我只是不确定如何最好地进行定时处理。
我的第一个想法是有一个由 cron
调用的 PHP 脚本,它可以工作,但我不确定这是否真的可扩展/解决这个问题的最佳方法(会创建一个服务器端守护进程)更好吗?我真的不知道该怎么做)。
我几乎只走了这条路,因为 PHP 是我唯一熟悉的服务器语言。我正在寻找替代方法(希望更好,意味着更快,对服务器的压力更小)方法来做到这一点,并且(因为这是一个个人项目),我愿意开始学习一门新语言(Ruby + Rails 是第一个)突然出现在我的脑海中)。
此外,也欢迎对系统的任何其他部分(除了定时处理之外)进行任何改进!我希望在这个项目之后能够扩展我的编码库。
由于我只是在计划这个,所以还没有代码可供查看(还!)
谢谢大家的建议!
-欧空局
I have a system that I'm trying to plan out, but I'm not sure how to attack it.
The system will take input from (hopefully many) clients and store it in a database (MySQL). That's easy (PHP scripts).
The part I'm not sure about is this: At a certain time interval (every five minutes), the server needs to process the data that the clients submitted in the last five minutes, and push the result (basically an average of the inputs) out to the clients that are currently connected (the 'push' part I think I have a plan for...using Socket.IO), along with having these results available for future requests (also not hard with a dynamic XML file with PHP). I'm just not sure how to best approach the timed processing.
My first thought was to have a PHP script called by cron
, which could work, but I'm not sure if that's really scalable/the best way to go about this (would making a server-side daemon be better? I really have little idea how to go about that).
I pretty much only went that route since PHP is the only server language I know well. I am looking for alternative (hopefully better, meaning faster and less strain on the server) methods to do this, and (since this is a personal project), I am willing to take up learning a new language (Ruby + Rails was the first to pop up in my mind).
Also any improvements any other parts of the system (other than the timed processing) are welcome as well! I'm looking to have expanded to my coding arsenal after this project.
Since I am just planning this, there is no code available to look at (yet!)
Thank you all for your suggestions!
-Esa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 MySQL,您可以使用 MySQL 事件调度程序: http://www.hashbangcode .com/blog/mysql-event-scheduler-352.html
或者如果您想为 cron-jobs 提供更通用的解决方案,您可以深入研究 JobScheduler:http://www.sos-berlin.com /modules/cjaycontent/index.php?id=124&page=osource_scheduler_quickstart_en.htm
Using MySQL you can either use MySQL Event Scheduler: http://www.hashbangcode.com/blog/mysql-event-scheduler-352.html
or if you like to have a more generic solution for cron-jobs, you can dig into JobScheduler: http://www.sos-berlin.com/modules/cjaycontent/index.php?id=124&page=osource_scheduler_quickstart_en.htm