Joel
Joel

Reputation: 11851

PHP swallowing exception

I'm trying to debug a PHP script that fails silently.

I've found where an exception is thrown, but the process exits before it can be caught.

The two try-catch blocks have been added by me. The surrounding code comes from 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";
        }
        //...
    }
    //...
}

The output is

START
WE DO GET HERE

Why would the exception be swallowed or cause the process to die?

Edit

It exits with status code 255

Running through 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 +++

It echo 'WE DO GET HERE', and then immediately starts to shutdown. The SHUTDOWN on fd 3 is socket to the database.

Upvotes: 0

Views: 725

Answers (2)

CodeOwl
CodeOwl

Reputation: 672

I've seen something similar to this, though in a different context of PHP. On CentOS 6.7 PHP 5.3 there's a bug where cURLs to an https url will simply kill the program. No errors will be thrown, so you can try-catch until you're blue in the face and it will never give you a friendly error message.

(You can read about it here if your interested: https://www.centos.org/forums/viewtopic.php?t=57970 https://bugzilla.redhat.com/show_bug.cgi?id=1249426)

I'm not suggesting that this has anything directly to do with your problem other than the fact that every now and again, a library -even a trusted one like cURL- will have a terrible run-time bug. I only found this after hugely verbose logging. I realize this question is a year old, but hopefully my tail of woe will be useful to someone else dealing with a "ninja" error like the kind you're describing.

Upvotes: 1

David Boskovic
David Boskovic

Reputation: 1519

You're experiencing an unreported parser error, read this question for more information: Parse errors are not displayed

But the basic answer is you need to add the following to your php.ini

error_reporting = E_ALL | E_STRICT

Also, your actual syntax error is on this line. You need the ending ;

        echo "START\n"

Upvotes: 1

Related Questions