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条)

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题