我正在尝试调试静默失败的PHP脚本。
我已经找到了抛出异常的位置,但是该进程会在被捕获之前退出。
我添加了两个try-catch块。周围的代码来自Magento。
class Varien_Image {
function __construct($fileName=null, $adapter=Varien_Image_Adapter::ADAPTER_GD2)
{
try {
$this->_getAdapter($adapter);
$this->_fileName = $fileName;
if (isset($fileName)) {
$this->open(); // throws here from a few frames deeper
}
} catch(Exception $e) {
echo "WE DO GET HERE\n";
throw $e;
}
}
//...
}
class Mage_Catalog_Model_Product_Image ... {
//...
public function getImageProcessor() {
//...
try {
echo "START\n";
$this->_processor = new Varien_Image($this->getBaseFile());
} catch(Exception $e) {
echo "BUT WE NEVER GET HERE - THE PROCESS EXITS INSTEAD\n";
}
//...
}
//...
}
输出
START
WE DO GET HERE
为什么会吞下异常或导致进程死亡?
修改
退出状态码为255
通过strace:
write(1, "WE DO GET HERE\n", 15WE DO GET HERE
) = 15
write(3, "\1\0\0\0\1", 5) = 5
shutdown(3, SHUT_RDWR) = 0
close(3) = 0
munmap(0x7f254d9f3000, 151552) = 0
close(2) = 0
close(1) = 0
munmap(0x7f254da1f000, 4096) = 0
close(0) = 0
munmap(0x7f254da20000, 4096) = 0
munmap(0x7f2548d95000, 266240) = 0
munmap(0x7f2548d54000, 266240) = 0
munmap(0x7f2548c91000, 266240) = 0
brk(0x691f000) = 0x691f000
brk(0x679f000) = 0x679f000
brk(0x641e000) = 0x641e000
brk(0x5b9e000) = 0x5b9e000
brk(0x4f5e000) = 0x4f5e000
brk(0x4dde000) = 0x4dde000
brk(0x4c5e000) = 0x4c5e000
brk(0x4ade000) = 0x4ade000
brk(0x47de000) = 0x47de000
brk(0x465e000) = 0x465e000
brk(0x439e000) = 0x439e000
brk(0x3e9e000) = 0x3e9e000
brk(0x3813000) = 0x3813000
brk(0x3693000) = 0x3693000
brk(0x3513000) = 0x3513000
brk(0x3393000) = 0x3393000
munmap(0x7f2548c50000, 266240) = 0
munmap(0x7f2548cd2000, 266240) = 0
munmap(0x7f2548d13000, 266240) = 0
munmap(0x7f2548dd6000, 266240) = 0
munmap(0x7f2549e93000, 2126744) = 0
munmap(0x7f2549c63000, 2293440) = 0
munmap(0x7f2549a3a000, 2264288) = 0
munmap(0x7f254a09b000, 2131176) = 0
munmap(0x7f254a2a4000, 2247424) = 0
munmap(0x7f254aa01000, 2151656) = 0
munmap(0x7f254a4c9000, 5471824) = 0
munmap(0x7f254ac0f000, 2164040) = 0
munmap(0x7f254ae20000, 2209936) = 0
munmap(0x7f254b03c000, 2267912) = 0
brk(0x2c3a000) = 0x2c3a000
munmap(0x7f254d89e000, 1052672) = 0
munmap(0x7f254d99f000, 266240) = 0
munmap(0x7f254d84f000, 323584) = 0
exit_group(255) = ?
+++ exited with 255 +++
它回应'我们在这里得到',然后立即开始关机。 fd 3上的SHUTDOWN是数据库的套接字。
答案 0 :(得分:1)
您正在体验未报告的解析器错误,请阅读此问题以获取更多信息: Parse errors are not displayed
但基本的答案是你需要将以下内容添加到你的php.ini
中error_reporting = E_ALL | E_STRICT
此外,您的实际语法错误在此行上。您需要结尾;
echo "START\n"
答案 1 :(得分:0)
虽然在PHP的不同上下文中,我已经看到类似的东西。在CentOS 6.7 PHP 5.3上有一个错误,其中一个https url的cURL将简单地杀死该程序。不会抛出任何错误,所以你可以尝试捕捉,直到你脸色发蓝,它永远不会给你一个友好的错误信息。
(如果您有兴趣,可以在这里阅读: https://www.centos.org/forums/viewtopic.php?t=57970 https://bugzilla.redhat.com/show_bug.cgi?id=1249426)
我并不是说这与你的问题有任何直接关系,除了这样一个事实,即一个库 - 即使像cURL这样的可信任的库 - 将会有一个可怕的运行时错误。我只是在大量冗长的日志记录后才发现这个。我意识到这个问题已经有一年了,但希望我的祸患对于处理你所描述的“忍者”错误的其他人有用。