duandu1049 2011-12-13 05:02
浏览 72
已采纳

当用户取消脚本时如何处理废弃的PID文件?

This is more of a question about best practices. My server allows users to convert fonts from one format to another using FontForge. To prevent collisions, only one font conversion is allowed at any given instance.

When one user initiates a conversion, a PID file is created which acts as a lock. If another user tries to initiate a conversion while the first conversion is still running, then the script will pause for a moment and check for the PID file again.

This repeats until the first process removes the PID file, thus unlocking access to FontForge. However, if the first user cancels the script before it finishes (by pressing the stop button on their browser), then the script exits before the PID file is removed. The second user will never be able to proceed.

What is the best way to handle this?

  • 写回答

2条回答 默认 最新

  • douya2007 2011-12-13 05:16
    关注

    Looking at this PHP Man page:

    http://php.net/manual/en/features.connection-handling.php

    I quote:

    You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects. This behaviour can be set via the ignore_user_abort php.ini directive as well as through the corresponding php_value ignore_user_abort Apache httpd.conf directive or with the ignore_user_abort() function. If you do not tell PHP to ignore a user abort and the user aborts, your script will terminate.

    The one exception is if you have registered a shutdown function using register_shutdown_function(). With a shutdown function, when the remote user hits his STOP button, the next time your script tries to output something PHP will detect that the connection has been aborted and the shutdown function is called. This shutdown function will also get called at the end of your script terminating normally, so to do something different in case of a client disconnect you can use the connection_aborted() function. This function will return TRUE if the connection was aborted.

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

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误