We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon crashing with "trap invalid opcode"

@phalcon devs...

I'm getting this in kern.log:

kernel: [ 5768.149406] traps: php-fpm[8559] trap invalid opcode ip:7f8cdf11c1e0 sp:7ffe385a55d0 error:0 in phalcon.so[7f8cded9a000+457000]

Unfortunately, I can't recompile PHP with --enable-debug flag to get you gdb output, but I can send over source code should anyone be willing to take a look.

Thank you.



51.3k
edited Dec '16

This is really weird. Below is the code that causing the crash:

<?php
new Phalcon\Mvc\Router;
?>

That's it - hitting that over HTTP causes the crash.

Any idea?

Latest Phalcon, PHP7.0, Ubuntu 16.04 64bit



51.3k

Looked at it closer and router is only crashing when trying to init default routes.

Thus, this is what causes router to crash:

new Phalcon\Mvc\Router\Route("#^/([\\w0-9\\_\\-]+)[/]{0,1}$#u", [
    "controller"=> 1
]);
edited Dec '16
//new Phalcon\Mvc\Router;
new Phalcon\Mvc\Router(); //try with () here

I use exactly the same setup as you, and never had issues with Router component.

Edit: () is not root cause of your problem, but rather your route pattern. Does that happen all the time or just sporadically?



51.3k

This works because it skips default routes init:

new Phalcon\Mvc\Router(false);

This crashes:

new Phalcon\Mvc\Router();

It happens every time. I am seriously worried now, as I have to port a project from Phalcon 1.3 to PHP7/Phalcon 3 combo. Gonna recompile php with --enable-debug flag.

PCRE might be your root issue here, and PHP7 if your route patterns worked on previous PHP and Phalcon versions. But 1.3... prior 2.0 Phalcon had no Zephir intermediate, that might be also your root cause of some other issues.



51.3k

I like your username btw. "Jonathan... It's showtime".

edited Dec '16

Thanks :)

Try setting your router only to read URLs from REQUEST_URI $_SERVER superglobal.

$di->setShared('router', function (){
// Phalcon\Mvc\Router has a default behavior that provides a very simple routing that always expects a URI that matches the following pattern: /:controller/:action/:params

    $router = new \Phalcon\Mvc\Router(false); //Create the router without default routes

    //we're using Front Page Controller pattern in relation from nginx -> Phalcon, so we need to read superglobal request params as a source for routing
    $router->setUriSource($router::URI_SOURCE_SERVER_REQUEST_URI);

    //Set whether router must remove the extra slashes in the handled routes
    $router->removeExtraSlashes(true);

    return $router;
});

And... Be careful what you wish for - it may come true.