doudiemei2013 2018-08-29 15:20
浏览 34

多个Cron作业或1个Cron作业启动多个进程?

I have a question for somebody with experience in using PHP for background jobs. I have a software (PHP) that people use to translate articles. There can be (sometimes) 50 article submissions in 5 seconds. I have a cron running every 5 seconds checking to see if there are translations in the mysql database, and if they are, it takes 15 at a time, and translates (curl get calling a translate script) them 1 by 1 in a for.

It's pretty slow, and I want some kind of multi threading. I cannot (and don't think it's necessary) to use pthreads. I was thinking if maybe I should make the cron job run every second

OR

Making 1 cron job run every 5 seconds, but from the cron job, start 10 different processes with exec, that each will take a translation. IS that wise? What do you recommend?

And if my idea is good (of spawning processes using exec), how can I spawn a process and not wait for it to finish (so simply start 15 processes and let them do it's job, in the background)?

I tried: exec('php index.php smallCron > /dev/null &');

But it does not work.

IF I replace /dev/null with a filename (let's say aaa.txt) then the script gets called, but "exec" hangs and waits for it to finish. IF I leave /dev/null there, nothing happens, the index.php is never called.

Thank you!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?