简体   繁体   English

在PHP中捕获后台进程错误?

[英]Catch background process error in PHP?

How can I catch a background process error in PHP? 如何在PHP中捕获后台进程错误? I am running some commands to convert a PDF but sometimes the process gets killed. 我正在运行一些命令来转换PDF,但是有时该过程会被终止。 Is there anyway to monitor if the process has been completed successful ? 无论如何,是否有必要监视该过程是否成功完成?

You can use system like flaging. 您可以使用类似标记的系统。 on start up of each background process keep a separate flag_processId = 0 for those process and on successful completion of that process update that flag to 1. and if that process getting any error in between and if it is detactable then update it to not completed flag (eg flag = 2). 在每个后台进程启动时,为这些进程保留一个单独的flag_processId = 0,并在该进程成功完成后,将该标志更新为1。如果该进程之间有任何错误,并且可确定,则将其更新为未完成标志(例如,标志= 2)。

By this you can keep track of that background process dynamically. 这样,您可以动态跟踪该后台进程。

or for detecting killing reason you can also use logging to log file. 或者,为了检测杀死原因,您也可以使用日志记录日志文件。

after each step in that process log completion of that step in log file, by this you can get where your process is getting killed. 在该过程中的每个步骤完成后,将该步骤记录到日志文件中,从而可以确定进程被杀死的位置。

Wrap the background process in a script which monitors it. 将后台进程包装在监视它的脚本中。

  • The script starts the PDF creator. 该脚本启动PDF创建器。
  • When the PDF creator is done, the script checks the output or exit code. PDF创建器完成后,脚本将检查输出或退出代码。
  • If the PDF creator crashes or is killed, the script can still take some action. 如果PDF创建者崩溃或被杀死,脚本仍然可以采取一些措施。
  1. Look into the server error logs. 查看服务器错误日志。
  2. Look into the error_log file in the folder where script is residing. 在脚本所在的文件夹中查看error_log文件。
  3. Try making small PDFs. 尝试制作小的PDF。 Most of the time, these PDF makers crash on large files / data. 大多数时候,这些PDF制造商在大文件/数据上崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM