duanjupiao4730 2013-01-25 10:31
浏览 87
已采纳

PHP set_time_limit然后重置数据库更改

I have an API which is used by a mobile app to create user profiles. It seems that occasionally the app is timing out and displays an error message but the server continues to create the profile. The result is that we have a few duplicate profiles.

I'm thinking that, as a 'quick fix' that doesn't require a complete re-architecture I could try setting the execution time of the PHP script to match the timeout limit in the app. My question is, if this time limit is reached, can I somehow execute an 'undo changes to the database' script, either automatic, or one I specify?

I know I should really be looking more into why the PHP is reaching timeout limit at all (it's a couple of minutes!), but I have already tweaked bits on the server, and mostly the execution time is just a few milliseconds. There are only a few cases of the timeout occurring. For the one example I'm looking at the minute the user is based in Israel. Is the network connectivity bad in Israel? Can anyone think of anything that could cause the behaviour I'm experiencing?

  • 写回答

2条回答 默认 最新

  • dt1888 2013-01-25 10:38
    关注

    One approach would be to use database transactions. I have experience in this with PostgreSQL, but I am sure MySql will do that too. You would wrap everything in a transaction. Then you can cancel the transaction when you detect failure, rolling back everything which belongs to the transaction.

    Then, you can't catch a script timeout as it is a fatal error, however a transaction should be automatically rolled back (canceled) if it does not get committed, so you should be set...

    Maybe it could work for you?

    References:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算