I want to try the ZeroMQ, and I write two php file, service.php and client.php.
I use the linux terminal to run service php /web/test/service.php
,it's ok, terminal print a "waiting for client connecting...".
but, I request my client.php through chrome explorer,error happened, I check my error.log,there is message "php fatal error: class 'ZMQContext' not found........"
and I use command php -m
to check my php extension, zmq
is already in that list.
The problem is that the ZMQ module is loaded in the PHP CLI (Command Line Interface) but it's not loaded into Apache. Therefore, service.php
runs smoothly from the Command Line but client.php
can't use ZMQContext because Apache does not load ZMQ.
There are two different .ini
-files. These probably are (but can be different, depending on your distro):
/etc/php5/apache2/php.ini
for Apache/etc/php5/cli/php.ini
for CLIHowever, all .ini
files from the /etc/php5/conf.d/
directory are loaded into both Apache and the CLI.
See also: PHP - An external Class/library is accessible from apache but not from phpunit (the exact opposite of your problem)
Checking (with phpinfo
) which php.ini files are loaded when requested via nginx (which probably means via php-fpm) - will almost certainly reveal that it loads different ini files than the cli. Assuming php-fpm usage, the following ini files are probably loaded:
/etc/php5/fpm/php.ini
/etc/php5/fpm/conf.d/*
and no zmq.ini file listed.
Follow the instructions for installing zmq on php, and create an ini file for zeromq (or copy the one from /etc/php5/cli/conf.d/
since evidently it's loaded for cli usage):
# /etc/php5/conf.d/zeromq.ini
extension=zmq.so
Then restart php-fpm
sudo /etc/init.d/php5-fpm restart
And zeromq should be available for use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With