PHP 内部 - 使用什么错误记录功能?

标签 php c

我正在编写一个 PHP 扩展(尽管它开始看起来很像一个 zend 扩展)。在某些情况下,它需要写入日志记录接口(interface)。

但是我看到 zend_error() 正在其他地方使用:

  • 在github上阅读源码发现zend/zend.h中声明了zend_error但是找不到对应的函数定义

  • 查看使用 zend_error 的上下文,我怀疑调用将被 set_error_handler 重新路由/转移

通常,日志记录将发生在 MINIT 和 MSHUTDOWN 中(假定由脚本定义的错误处理程序不会产生任何影响),但也可能有时间介于两者之间 - 我正在寻找一些一致性。因此试图了解该机制的工作原理。

在 MINIT/MSHUTDOWN 中使用 zend_error() 是否安全?

如何确保我始终调用默认错误处理程序?

最佳答案

好吧,我在 PHP Wiki 中找到了这个.我认为这是旧的,但我想它仍然适用于 Zend3:

Don't use zend_error

zend_error() should only be used inside the engine. Inside PHP extensions only PHP's error functions shoudl be used. Typically php_error_docref() is the best choice. php_error_docref() will extend the error message by extra information, like the current function name and properly escape output where needed. zend_error() is used by the Zend Engine due to PHP's modular architecture where the Zend Engine and TSRM should be compilable without other parts of PHP. The engine therefore can not use PHP level APIs. This limitation does not exist in extensions.

这对我来说意味着 zend_error 是为在引擎中使用而编写的,而不是设计为用于构建扩展的工具之一。出于这个原因,您不太可能找到涵盖您所询问的详细信息的文档,而且即使它确实对您可靠地工作,也可能不会继续这样做。

关于PHP 内部 - 使用什么错误记录功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52169465/

相关文章:

php - 每次重新加载时删除 Laravel 的存储/ View 文件

php - 将值从 PHP 粘贴到 JavaScript

c - ANSI C getc 在 Linux 而不是 OS X 上导致段错误

c - 汇编函数具有相同的名称,后缀为 ..0 和 ..1

c - 如何在同一个共享内存段中正确地拥有多个变量

php - Paypal IPN 自定义变量

php - 在 Sphinx 中使用 MVA 属性

php - 匹配交替子模式的正则表达式模式

c - 使用#define 重新定义枚举枚举数

c - 如何在 C 中获取 DateSeparator