Trouble with eaccelerator and Klein
tarampampam opened this issue · 0 comments
I have installed Apache + PHP on production server:
$ httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 19 2015 21:43:13
$ php -v
PHP 5.4.16 (cli) (built: Jun 23 2015 21:17:27)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with eAccelerator v1.0-dev, Copyright (c) 2004-2012 eAccelerator, by eAccelerator
And i catched an error:
PHP Fatal error: require(): Failed opening required '' (include_path='.:/usr/share/pear:/usr/
share/php') in /{path}/vendor/klein/klein/src/Klein/Klein.php on line 382
While opening any page. On line 382 we can find:
public function with($namespace, $routes)
{
$previous = $this->route_factory->getNamespace();
$this->route_factory->appendNamespace($namespace);
if (is_callable($routes)) {
if (is_string($routes)) {
$routes($this);
} else {
call_user_func($routes, $this);
}
} else {
require $routes;
// ^^^^^^^^^^^^^^^^
}
$this->route_factory->setNamespace($previous);
}
Ok. Lets look into my code:
// App::Router() = class Router extends \Klein\Klein {}
App::Router()->with('/', function () {
App::Router()->respond('', function () {
// ...
});
App::Router()->respond('pages/[*:page].[*:ext]?', function ($request) {
// ...
});
});
So, to function with($namespace, $routes)
must be passed anonymous function (callable).
Just for testing i added var_dump(is_callable($routes)); die();
after $this->route_factory->appendNamespace($namespace);
in function with($namespace, $routes)
.
Testing on local server (Windows, Apache 2.2.31, PHP 5.3.29 without eaccelerator):
bool(true)
Testing on test server (CentOS, Apache 2.4.6, PHP 5.4.16 without eaccelerator):
bool(true)
Testing on production server (CentOS, Apache 2.4.6, PHP 5.4.16 with eaccelerator):
bool(false)
False? WTF? As a quick fix i added to .htaccess
:
<IfModule mod_php5.c>
php_flag eaccelerator.enable 0
php_flag eaccelerator.optimizer 0
</IfModule>
And then all works nornally. But - whats happend? And how i can fix this without disableing php eaccelerator
?
Update 1:
eAccelerator not compatible with anonymous function/closure under php 5.4.6
Update 2:
Added this code to project init:
if (ini_get('eaccelerator.enable')) {
ini_set('eaccelerator.enable', 0);
ini_set('eaccelerator.optimizer', 0);
}
Update 3:
eAccelerator removed from production server. Installed ZendOPcache:
$ nano /etc/php.d/eaccelerator.ini
# comment all lines
$ yum install php-pecl-zendopcache
$ service httpd restart