douzha6055 2012-10-12 17:49
浏览 46

在不使用max_execution_time的情况下使操作成为原子

I have set up a cron job (PHP script), which does the following job :

1. Read all of the unseen emails, using imap
   1.1  For each email readed
   1.2. Fetches the details and save detail in database
   1.3. Moves email to other mailbox named "Processed"
   1.4. Goto step 1.1

But If the PHP script stops or fails executing, after step 1.2 but before 1.3, the emails will be re-processed, which is the problem here.

As we all know, the processing time depends on many factors such as server load and the number of emails to be processed, so I don't think that setting up max_execution_time will help.

How do I make this atomic? Any ideas? (I can change the process flow too, if you have any ideas about a different process flow).

Edit: Suppose that the email moved, and it was just going to commit, but the PHP script stops? What would happen then is that the email would move without a record being stored.

  • 写回答

1条回答 默认 最新

  • doulu5717 2012-10-12 17:51
    关注

    You could put step 1.2 into a database transaction, then if step 1.3 fails, you would rollback the transaction.

    If you have a transaction, and a "commit" is not explicitly called (ie via timeout, or you just forgot to call commit), then it is automatically assumed to rollback.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)