问题
I'm running web server on nginx 1.4.6 and php 5.5 inside a virtualized machine with Ubuntu 14.04 and need to install ZeroMQ extension. I have followed the instructions on ZMQ (the section To build on UNIX-like systems), added php language binding as instructed here, compiled it against my version of php and added the line
extension=zmq.so
to /etc/php5/cli/php.ini
as well as to /etc/php5/fpm/php.ini
, which are my only .ini
files.
After restarting nginx
and php-fpm
the php -i
shows following:
$ php -i | grep -i zmq
zmq
ZMQ extension => enabled
ZMQ extension version => @PACKAGE_VERSION@
libzmq version => 4.0.4
So the ZMQ module is installed in cli, but when I visit a page with phpinfo();
I don't see the ZMQ module configuration section and when I access the page, where the code $context = new \ZMQContext();
is invoked, I get the error message:
Class 'ZMQContext' not found".
The ZMQ module is obviously loaded properly within the cli but for some reason it is not recognised in php-fpm. I have double checked that the fpm php.ini
is loaded and that the line with extension is there.
I also have a script push-server.php
that runs a separate websocket server in a loop with Ratchet and listens for incoming messages to be pushed to subscribers:
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
require dirname(__DIR__) . '/app/libs/Pusher/Pusher.php';
$loop = React\EventLoop\Factory::create();
$pusher = new App\Libs\Pusher\Pusher; // my own pusher implementation
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555');
$pull->on('message', [$pusher, 'onMessageEntry']);
$pull->on('subscribe', [$pusher, 'onSubscribe']);
$webSock = new React\Socket\Server($loop);
$webSock->listen(8099, '0.0.0.0');
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
new Ratchet\Wamp\WampServer(
$pusher
)
)
),
$webSock
);
$loop->run();
After executing php push-server.php
it runs without errors so the ZMQ module is loaded properly in cli.
I have already tried stuff suggested here, but no luck. There is a similar question here, but focused on windows and wamp server and so far without answer.
Does anyone have any idea why this is happening? It will be highly appreciated.
回答1:
The problem disappeared after upgrading PHP to 5.6, all modules load without troubles.
来源:https://stackoverflow.com/questions/38054563/class-zmqcontext-not-found