记录致命错误(Logging fatal errors)
我有一个简单的日志记录类将日志消息写入日志文件。
class Logger { // write a custom message to the log file public static function log($msg) { $hndl = fopen('log.log'); fwrite($hndl, $msg); fclose($hndl); } // write errors to log file public static err_callback($eno, $emsg) { Logger::log($msg); return false; } // write fatal errors to log file public static ftl_callback() { $error = error_get_last(); if ($error['type'] == E_ERROR) { Logger::log($error['message']); } } }
我注册了err_callback和ftl_callback函数,将PHP错误写入日志文件,如下所示:
register_shutdown_function('Logger::ftl_callback'); set_error_handler('Logger::err_callback');
直接调用Logger :: log()或发生非致命错误时,日志记录工作正常,但是在致命错误上我收到以下错误:
警告:fopen(log.log):无法打开流:在第181行的E:_websites \ c \ phpSource \ Logger.php中拒绝权限
发生致命错误时,为什么会收到“权限被拒绝”错误? 这是PHP的问题还是配置问题? 如果它是PHP,那么它有一个解决方法吗?
环境:PHP 5.3.8 IIS 6.1 Windows 7
所有帮助赞赏。
I have a simple logging class to write log messages into a log file.
class Logger { // write a custom message to the log file public static function log($msg) { $hndl = fopen('log.log'); fwrite($hndl, $msg); fclose($hndl); } // write errors to log file public static err_callback($eno, $emsg) { Logger::log($msg); return false; } // write fatal errors to log file public static ftl_callback() { $error = error_get_last(); if ($error['type'] == E_ERROR) { Logger::log($error['message']); } } }
I register the err_callback and ftl_callback functions to write PHP errors to the log file as follows:
register_shutdown_function('Logger::ftl_callback'); set_error_handler('Logger::err_callback');
When calling Logger::log() directly or when a non-fatal error occures then logging works fine, however on fatal errors I receive the following error:
Warning: fopen(log.log): failed to open stream: Permission denied in E:_websites\c\phpSource\Logger.php on line 181
Why do I receive "Permission denied" error when fatal error occures? Is it an issue with PHP or a configuration issue? If it is PHP then is there a workaround for it?
Environment: PHP 5.3.8 IIS 6.1 Windows 7
All help appreciated.
原文:https://stackoverflow.com/questions/22440046
最满意答案
是的,也许线程应该是STA
I found that for the solution to this problem there was no requirement to alter the threading model. The issues had nothing to do with multi-threading. It was the networking code that was running behind the scenes in it's own thread that was creating exceptions and causing the main thread to fail (even though it was not supposed to)
Removing the Context Posting code consistently caused errors (of a different nature) that looked like the same thing, but they were consistent rather than random like the network code.
IMO I would recommend leaving threading apartments alone (use the defaults).
相关问答
更多-
这可能是由于运行时版本不匹配。 尝试以下操作: 为IDE创建一个.config文件(例如IDE可执行文件的EXE名称+ .config)。 在其中粘贴以下内容:
-
将ActiveX exe项目加载到vb6 IDE中。 根据需要设置断点。 按F5(或使用鼠标单击开始按钮图标)。 然后启动桌面应用程序。 当它实例化您的应用程序时,它将连接到IDE中运行的副本。 请注意,您不会在任务管理器中看到ActiveX exe。 Load your ActiveX exe project into the vb6 IDE. Set your breakpoints as desired. Press F5 (or use the mouse to click the start bu ...
-
使C#类工作VB6(Making C# class working VB6)[2023-04-14]
将.NET组件公开给COM Exposing .NET Components to COM -
无法找到vb6的dll?(Unable to find dll of vb6?)[2023-05-12]
将VB 6应用程序迁移到.NET需要相当多的工作。 通常不到一个完整的重写,但在处理一个非平凡的应用程序时仍然是一个相当大的事业。 因此,如果您只想进行一两次小改动,那么您应该坚持使用VB 6。 如果您决定进行转换,是的,您需要安装VB 6才能访问这些控件库。 但您可能不想继续使用它们。 它们几乎都是古老的控件,取而代之的是.NET Framework中更新更好的选项。 例如,现在应该使用System.IO.Ports.SerialPort类而不是AxMsCommLib 。 这是我上面讨论过的“工作”部分。 ... -
VB6:如何添加Inet组件?(VB6: how to add Inet component?)[2022-11-06]
项目(菜单) - >组件 - >选中“Microsoft Internet Transfer Controls 6.0”(MSINET.OCX)。 现在您应该在工具栏上有Inet图标。 Project (menu) --> Components --> Check "Microsoft Internet Transfer Controls 6.0" (MSINET.OCX). Now you should have the Inet icon on the toolbar. -
Visual Build Pro 。 如果你仍然陷在VB6的土地上,并且不得不打造专业产品,我强烈建议你看看这款产品。 它有一个免费的试用版,值得每一分钱(加上它在.Net和其他平台上的持续集成方面做得相当不错)。自从我们开始使用它以来,它在每个版本中都从DLL地狱中拯救了我们。 在VB6中,我没有其他方法可以创建体面的构建框。 Visual Build Pro. If you are still stuck in VB6 land, and have to build professional produ ...
-
当Enabled = False时,VB6 TreeView未显示为灰色(VB6 TreeView not showing grayed when Enabled=False)[2022-12-16]
我以前从未注意到这一点。 你可以编写一个解决方案,但如果你有很多节点会受到伤害。 If (TreeView1.Enabled) Then SetTreeViewColor vbWindowText Else SetTreeViewColor vbGrayText End If Private Sub SetTreeViewColor(ByVal vColor As SystemColorConstants) Dim objNode As Node For Each obj ... -
是的,也许线程应该是STA I found that for the solution to this problem there was no requirement to alter the threading model. The issues had nothing to do with multi-threading. It was the networking code that was running behind the scenes in it's own thread that was ...
-
好吧,我找到了解决方案。 我不确定它是不是正确的。 但我发现其他帖子类似于这个问题,谈到用/tlb参数运行regasm来创建一个类型库,然后在VB6中引用它。 当我将应用程序部署到另一台机器时,我不想拥有该引用,所以我忽略了这些建议。 最后,我决定尝试使用该参数并引用类型库,然后VB6 IDE调试工作。 但是奇怪的部分(对我来说很好)是,然后我删除了引用,VB6 IDE继续工作。 所以,不知何故,在我删除引用后,在IDE中运行时,在VB6中添加引用确实可以使其工作。 希望这可以帮助其他任何可能在新的Wind ...
-
在我的VB6 IDE中设置ImageMagick时遇到问题(having an issue with setting up ImageMagick in my VB6 IDE)[2022-06-03]
看起来你已经安装了64位版本的DLL。 如果他们提供32位安装可以解决您的问题? VB6是一个32位应用程序 It looks like you've installed the 64 bit version of the DLL. If they offer a 32 bit install that might solve your problem? VB6 is a 32 bit application