PHP线程池? [英] PHP thread pool?

查看:72
本文介绍了PHP线程池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已预定CRON作业每4小时运行一次,需要收集用户帐户信息。
现在我想加快速度,并在几个进程之间拆分工作,并使用一个进程用从其他进程检索的数据更新MySQL DB。



在JAVA我知道有一个线程池,我可以奉献一些线程来完成一些工作。



如何在PHP中做?

欢迎任何建议。



感谢

解决方案

正如其他人所说,分叉过程比使用PHP生成线程更容易。但是为什么你认为有一个专用线程将结果写回数据库是一个好主意?虽然这对线程而不是进程稍微简单一些,但是它仍然是一个复杂的开销,似乎不会为总体目标增加任何价值。



确实,很容易从cron启动脚本的几个实例(使用一些参数来分区数据),而不是从PHP代码中启动一个fork - 而不用担心将数据记录回数据库的任何瓶颈。 p>

C。


I have scheduled a CRON job to run every 4 hours which needs to gather user accounts information. Now I want to speed things up and to split the work between several processes and to use one process to update the MySQL DB with the retrieved data from other processes.

In JAVA I know that there is a thread pool which I can dedicate some threads to accomplish some work.

how do I do it in PHP?

Any advice is welcome.

Thank

解决方案

As others have said, forking processes is easier than spawning threads with PHP. But why do you think that having a single dedicated thread to write the results back to the database is a good idea? Although this is slightly simpler to do with threads rather than processes, its still a complex overhead which doesn't seem to add any value to the overall objective.

Indeed, its a lot simpler to start up several instances of the script (with some parameter to partition the data) from cron rather than initiating a fork from within the PHP code - and not bother with any bottleneck for recording the data back into the database.

C.

这篇关于PHP线程池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆