PHP 高级作业队列
我正在使用 cron 制作一个一天包含 2000 个作业的脚本(意味着这是服务器端并自动执行所有作业。),
但该作业需要同时运行 10 个(或指定数量的作业)作业。
就像你看到 IDM(互联网下载管理器)一样,有一个队列功能,它一次运行多个作业,如果有一个作业完成,它就会启动另一个作业。我想要这样的东西..
我该怎么做?
I am making a script with 2000 jobs in a day using cron (means that is server side and automatically do all jobs.)
but the job require to run simultaneously 10 (or specified no. of jobs ) jobs .
like if u see IDM(internet download manager ) there is a queue function it run multiple jobs at a time and if any complete it start another . i want something like this ..
how can i do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不同意创建自己的作业队列处理程序。您将会遇到一些您没有预料到的问题,而现有项目已经遇到并处理了这些问题。
我会选择类似 beanstalkd 的东西,构建一个通用脚本来处理队列中的作业,然后生成
$x
子进程来遍历并处理它们。I disagree with making your own job queue handler. You're going to run into problems down the line that you didn't anticipate and that existing projects have already met and dealt with.
I'd go with something like beanstalkd, build a generic script to handle the jobs in the queue, then spawn
$x
child processes to go through and process them.还有 WordPress 作业队列 - 请参阅 http://code.trac.wordpress.org/wiki/JobsDocs (我没有使用过,所以不能保证)
There's also the wordpress job queue - see http://code.trac.wordpress.org/wiki/JobsDocs (I've not used it, so can't vouch for it)
您最好编写自己的作业队列处理程序。
您可以使 phpignore_user_abort 并使其成为守护进程...
但在执行此操作之前请确保您对它有一定的控制权。
You would be well off writing your own job queue handler.
You could make php ignore_user_abort and make it a daemon process too...
But make sure you have some control over it before you do that.
您可以继续编写自己的自定义作业队列处理程序。每个作业生成一个单独的进程,并继续在父进程中收集响应。前一个作业完成后重新启动新作业。
或者,您也可以深入使用 Gearman (特别是如果您有多个并行运行作业的盒子)。还可以查看此处提出的解决方案 asynchronous-processing-with-php-one -每个工作的工人
You can either go ahead and write your own custom job queue handler. Spawn a separate process per job, and keep collecting the response in the parent process. Restart new jobs when previous one's have finished.
Or alternately you can dig into using Gearman (specially if you have multiple boxes running jobs in parallel). Also do view solutions proposed here on asynchronous-processing-with-php-one-worker-per-job