Hi PhalconPHP!
My PhalconPHP 2.1.0-RC1 application was working fine, until I started interacting with models. Now, any code that uses a model causes the application to crash with a segmentation fault:
$ tail /var/log/apache2/error.log
[Sun Apr 24 17:56:33.085807 2016] [core:notice] [pid 17024] AH00051: child pid 17065 exit signal Segmentation fault (11), possible coredump in /etc/apache2
Apparently, there is a known issue with models and segmentation faults, which is related to PHP 7 test related issues. However, I'm new to PhalconPHP, and I want to be sure I'm not missing something stupid before I submit an issue on Github.
I'm using the following software:
- Ubuntu 14.04 (last
apt-get update && apt-get upgrade
4/24/16) - Apache 2.4.12
- MySQL 5.6.30
- PHP 7.0.5
- Zephir 0.9.2a-dev
- Phalcon 2.1.0-RC1 (last
git pull
andzephir build
4/24/16)
I have a groups
table:
mysql> SHOW CREATE TABLE `groups`;
CREATE TABLE `groups` (
`id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(15) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ux_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8
The groups
table has a few groups:
mysql> SELECT * FROM groups;
+----+------+
| id | name |
+----+------+
| 2 | foo |
| 1 | bar |
+----+------+
2 rows in set (0.05 sec)
I have a Group
model:
<?php
namespace App\Model;
/**
* A group
*/
class Group extends \Phalcon\Mvc\Model
{
/* !Private properties */
/**
* @var int the group's id
*/
private $id;
/**
* @var string the group's *unique* name (lower-case and plural by convention)
*/
private $name;
/* !Get methods */
/**
* Returns the group's id
*
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* Returns the group's name
*
* @return string
*/
public function getName(): string
{
return $this->name;
}
/* !Set methods */
/**
* Sets the group's name
*
* @param string $name
* @return self
*/
public function setName(string $name): self
{
$this->name = strtolower($name);
return $this;
}
/* !Magic methods */
/**
* Called to initialize the model
*
* @return self
*/
public function initialize(): self
{
$this->setSource('groups');
return $this;
}
}
I added App\Model\Group::findFirst(1)
to my index.php
(of course, it doesn't live here normally):
// define the root directories
define('ROOT_PROJECT', realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR);
define('ROOT_APPLICATION', realpath(__DIR__ . '/../app/') . DIRECTORY_SEPARATOR);
define('ROOT_DOCUMENT', __DIR__ . DIRECTORY_SEPARATOR);
// include the vendor autoloader
require ROOT_PROJECT . 'vendor/autoload.php';
// include the application autoloader
require ROOT_APPLICATION . 'autoload.php';
// include the services configuration (defines $di)
require ROOT_APPLICATION . 'services/services.php';
// if the application is in development
if ($di->get('environment')->isDevelopment()) {
(new \Phalcon\Debug())->listen();
}
// this causes a segmentation fault!
\App\Model\Group::findFirst(1);
// don't start the application; we're debugging stuff
// echo (new \Phalcon\Mvc\Application($di))->handle()->getContent();
When I go to my development site, the application crashes, and Safari displays an error message saying, "Safari can't open the page, because the server unexpectedly dropped the connection."
However, I can tail
Apache's error logs and see PHP encountered a segmentation fault:
$ tail /var/log/apache2/error.log
[Sun Apr 24 17:56:33.085807 2016] [core:notice] [pid 17024] AH00051: child pid 17065 exit signal Segmentation fault (11), possible coredump in /etc/apache2
I tried to use gdb
to troubleshoot the issue:
$ gdb php
(gdb) run "path/to/index.php"
Program received signal SIGSEGV, Segmentation fault.
0xb5e41e76 in zephir_call_user_function () from /usr/lib/php/20151012/phalcon.so
(gdb) bt
#0 0xb5e41e76 in zephir_call_user_function () from /usr/lib/php/20151012/phalcon.so
#1 0xb5e431cb in zephir_call_class_method_aparams () from /usr/lib/php/20151012/phalcon.so
#2 0xb5e44344 in zephir_create_instance_params () from /usr/lib/php/20151012/phalcon.so
#3 0xb5d01e20 in zim_Phalcon_Di_get () from /usr/lib/php/20151012/phalcon.so
#4 0x80287668 in execute_internal ()
#5 0x801edf3f in dtrace_execute_internal ()
#6 0xb5e42ef5 in zephir_call_user_function () from /usr/lib/php/20151012/phalcon.so
#7 0xb5e431cb in zephir_call_class_method_aparams () from /usr/lib/php/20151012/phalcon.so
#8 0xb5c5d0dd in zim_Phalcon_Mvc_Model_Manager_createBuilder () from /usr/lib/php/20151012/phalcon.so
#9 0x80287668 in execute_internal ()
#10 0x801edf3f in dtrace_execute_internal ()
#11 0xb5e42ef5 in zephir_call_user_function () from /usr/lib/php/20151012/phalcon.so
#12 0xb5e431cb in zephir_call_class_method_aparams () from /usr/lib/php/20151012/phalcon.so
#13 0xb5dd1cbf in zim_Phalcon_Mvc_Model_find () from /usr/lib/php/20151012/phalcon.so
#14 0x80287668 in execute_internal ()
#15 0x801edf3f in dtrace_execute_internal ()
#16 0x8027cd24 in ?? ()
#17 0x8023acfa in execute_ex ()
#18 0x801ede3d in dtrace_execute_ex ()
#19 0x80288fcb in zend_execute ()
#20 0x801fd6f0 in zend_execute_scripts ()
#21 0x8019cc76 in php_execute_script ()
#22 0x8028b060 in ?? ()
#23 0x80071187 in main ()
(gdb) f
#0 0xb5e41e76 in zephir_call_user_function () from /usr/lib/php/20151012/phalcon.so
(gdb) info f
Stack level 0, frame at 0xbfffb860:
eip = 0xb5e41e76 in zephir_call_user_function; saved eip = 0xb5e431cb
called by frame at 0xbfffb8d0
Arglist at 0xbfffb858, args:
Locals at 0xbfffb858, Previous frame's sp is 0xbfffb860
Saved registers:
ebx at 0xbfffb84c, ebp at 0xbfffb858, esi at 0xbfffb850, edi at 0xbfffb854, eip at 0xbfffb85c
(gdb) info args
No symbol "args" in current context.
I did some sanity checking by making some changes to my index.php
:
// continued from above...
// comment out the problem line
// \App\Model\Group::findFirst(1);
$group = new \App\Model\Group();
$meta = $di->get('modelsMetadata');
$strategy = $meta->getStrategy();
echo '<p>' . get_class($meta) . '</p>';
echo '<p>' . get_class($strategy) . '</p>';
echo '<p>' . var_dump($strategy->getMetaData($group, $di)) . '</p>';
This produces the following output:
Phalcon\Mvc\Model\MetaData\Memory
Phalcon\Mvc\Model\MetaData\Strategy\Introspection
array(12) { [0]=> array(2) { [0]=> string(2) "id" [1]=> string(4) "name" } [1]=> array(1) { [0]=> string(2) "id" } [2]=> array(1) { [0]=> string(4) "name" } [3]=> array(2) { [0]=> string(2) "id" [1]=> string(4) "name" } [4]=> array(2) { ["id"]=> int(0) ["name"]=> int(2) } [5]=> array(1) { ["id"]=> bool(true) } [8]=> string(2) "id" [9]=> array(2) { ["id"]=> int(1) ["name"]=> int(2) } [10]=> array(0) { } [11]=> array(0) { } [12]=> array(0) { } [13]=> array(0) { } }
However, adding a call to getAttributes()
causes a segmentation fault:
// continued from above...
// comment out the problem line
// \App\Model\Group::findFirst(1);
$group = new \App\Model\Group();
$meta = $di->get('modelsMetadata');
$strategy = $meta->getStrategy();
echo '<p>' . get_class($meta) . '</p>';
echo '<p>' . get_class($strategy) . '</p>';
echo '<p>' . var_dump($strategy->getMetaData($group, $di)) . '</p>';
// add this line to produce a segmentation fault
echo '<p>' . var_dump($meta->getAttributes($group)) . '</p>';
Phew! Any ideas?
I'm sorry for the wall of text, but thank you for any help! PhalconPHP is super fast, but more importantly, it's just a great framework! Thank you for your hard work PhalconPHP Team!
EDIT: Whoops! I called it Model::find() instead of Model::findFirst() in my title and description here. Sorry for the confusion.