Class ZMQContext not found even though ZMQ is installed

12,589

Solution 1

If the extension is enabled you still need to use this:

use \ZMQContext;
use \ZMQ;

(or alternatively directly access them using a leading "\")

Solution 2

I have not used ZMQ but this seems like a configure problem.

First, run PHP in cli and in apache can use different php.ini

Eg in ubuntu 12.04:

/etc/php5/apache2/php.ini is used for apache
/etc/php5/cli/php.ini is used for cli

To check if ZMQ is currently loaded in apache, create a php file contains phpinfo(); and check it's output through web browser, there should be some info about ZMQ, use ctrl-f to search for it.

In cli, php -m will show loaded/compiled module or extension.

Second, ZMQ version

I can't thought other reason than you used a ZMQ version which hasn't ZMQContext ? You could check ZMQ document and the version you used.

(Deleted, should not be this problem according error message), namespace

if ZMQ is currectly loaded, and your code still doesn't work, the another possible reason is use of namespace. If your post.php is like

<?php
namespace Some\NameSpace;
$context = new ZMQContext();

Then it means ZMQContext in namespace Some\NameSpace, the full quanlified classname is Some\NameSpace\ZMQContext, which doesn't exists. So you may need use \ZMQContext for class out of current namespace.

Share:
12,589

Related videos on Youtube

sveti petar
Author by

sveti petar

Updated on September 16, 2022

Comments

  • sveti petar
    sveti petar over 1 year

    First of all, yes I am aware that there is a very similar question out there, but the answer given there doesn't apply to my situation, and there's no indication that it fixed the other person's problem either.

    I have ZMQ installed on my Apache server, according to the tutorial found in the Racthet documentation. I installed everything successfully after a lot of frustration, and I am ready to run an example. The simple PHP script is placed in post.php and features this line (after some rather trivial PHP, setting variables etc):

    $context = new ZMQContext();
    

    However, it throws this error:

    Fatal error: Class 'ZMQContext' not found in /home/lights/public_html/apps/post.php on line 12
    

    I have included extension=zmq.so at the end of my only used php.ini file, as the zeromq documentation suggested. To make sure Apache is loading the same php.ini as the page, I checked. Apache gave me exactly the same info as running phpinfo() on the page:

    Configuration File (php.ini) Path   /usr/local/lib
    Loaded Configuration File   /usr/local/lib/php.ini 
    

    From this I concluded that the same error should appear if I run php post.php from the terminal. However, no error was shown in this case - it seems the PHP code did its part. So, I have eliminated the only possible root cause that I have found in my search so far, and I am looking for an alternative.

    Anyone have a solution, suggestion, idea, anything at all that could help clear this up?

  • sveti petar
    sveti petar over 10 years
    I have eliminated options 1 and 3 (checked configuration and made sure I have the latest version of ZMQ). I'm not sure I understand option #2, can you clarify with some more detail?
  • Jasper N. Brouwer
    Jasper N. Brouwer over 10 years
    Namespaces are not the issue here, because PHP complains about ZMQContext, not Some\NameSpace\ZMQContext.
  • Fwolf
    Fwolf over 10 years
    @jovan If you have latest verion of ZMQ, suggested to check #1 through phpinfo();