ZMQContext class not found even if ZMQ is set

First of all, yes, I know that there is a very similar question, but the answer given there does not apply to my situation, and there is no indication that he also fixed the problem of another person.

I have ZMQ installed on my Apache server according to the manual contained in the Racthet documentation. I put everything to success after many disappointments, and I am ready to give an example. A simple PHP script is placed in post.php and has this line (after some pretty trivial PHP setting variables, etc.):

 $context = new ZMQContext(); 

However, this causes this error:

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

I included extension=zmq.so at the end of my only used php.ini file, as the zeromq documentation suggested. To verify that Apache loads the same php.ini as the page, I checked. Apache gave me exactly the same information as phpinfo () on the page:

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

From this, I came to the conclusion that the same error should appear if I ran php post.php from the terminal. However, in this case no error was shown - it seems that the PHP code has done its part. So, I have eliminated the only possible reason that I have found in my search so far, and I am looking for an alternative.

Does anyone have a solution, suggestion, idea, anything at all that could help clarify this?

+6
source share
4 answers

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

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

For example, 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 loading in apache, create a php file containing phpinfo(); , and check its output through a web browser, there should be some information about ZMQ, use ctrl-f to search.

In cli php -m , the loaded / compiled module or extension will be displayed.

Secondly, the ZMQ version

I can’t think of a different reason than you used the version of ZMQ that does not have ZMQContext? You can check the ZMQ document and the version you used.

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

if ZMQ is loaded correctly and your code is still not working, another possible reason is the use of a namespace. If your post.php is like

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

Then it means ZMQContext in the Some \ NameSpace namespace, the full quanlified class name is Some \ NameSpace \ ZMQContext, which does not exist. Therefore, you may need to use \ZMQContext for a class from the current namespace.

+3
source

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

 use \ZMQContext; use \ZMQ; 

(or, alternatively, directly access them using the leading "\")

+2
source

You need to restart Apache before using the new extensions. mod_php does not add modules at runtime

0
source

If you use Wampserver, copy the libzmq.dll file to C:\wamp64\bin\apache\apache2.4.17\bin and restart wamp.

-2
source

Source: https://habr.com/ru/post/958958/


All Articles