Category Archives: PHP

[Solved] Received subscribe acknowledgement with invalid QoS values from the broker

Server: emqx

Client: php-mqtt/client 3.x

PHP≥7.4

  • need
    • The project needs to customize the offline and online of the subscription client
  • code
    $server   = 'emqx server url';
    $port     = 1883;
    $clientId = 'sys_client';
    $username = 'test';
    $password = '12345678';
    $topics='$SYS/brokers/+/clients/#';//Subscription client online and offline
    $mqtt = new \PhpMqtt\Client\MqttClient($server, $port, $clientId);
    $connectionSettings = (new \PhpMqtt\Client\ConnectionSettings)
        ->setUsername($username)
        ->setPassword($password);
    
    $mqtt->connect($connectionSettings, true);
    $mqtt->subscribe($topics, function ($topic, $message) {
    			echo sprintf("Received message on topic [%s]: %s\n", $topic, $message);
    		}, 0);
    $mqtt->loop(true);
    $mqtt->disconnect();
    
  • Why is there an exception?
    Received subscribe acknowledgement with invalid QoS values from the broker.
    
  • How to solve it?
    • Refer to the ACL documentation of EMQX for rule setting: https://www.emqx.io/docs/zh/v4.3/advanced/acl-file.html
    • Default acl.conf
      {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
       
      {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
       
      {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
       
      {allow, all}.
      
    • Modify acl.conf, for the sake of security, I only allow the specified ip subscription here$SYS/brokers/+/clients/#
      {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
       
      {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
      
      #Specify ip subscription
      {allow, {ipaddr, "127.0.0.1"}, subscribe, ["$SYS/brokers/+/clients/#"]}.
      #Allow all clients to subscribe
      #{allow, all, subscribe, ["$SYS/brokers/+/clients/#"]}.
      
      {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
       
      {allow, all}.
      
    • Then, run it through the command line, it should not report an error

[Solved] PHP7.3 Error: undefined function simplexml_load_string()

Usually this situation is caused by the php extension module not having simplexml installed.

yum install php73-php-simplexml //install simplexml
systemctl restart php73-php-fpm  //restart php

If it is another version you can replace 73 accordingly
Then print phpinfo() and see the following module, then the problem is solved

[Solved] APCU Exetend php-fpm Start Error: PHP Startup: apc_mmap: mmap failed: inUnknown on line 0

When the APCU extension is installed and PHP FPM is started, an error is reported: Note: PHP message: PHP fatal error: PHP startup: APC_ mmap: mmap failed: in Unknown on line 0

The reason is shm_size setting is too large.

Solution: Just set shm_size to make the size configuration smaller

As follows:
apc.shm_size=1024M

apc.shm_size=1024M

[Solved] php -v Error: error while loading shared libraries: libonig.so.5:cannot open share directory

Currently from PHP5 6 when upgrading to PHP 7.4, directly replace the compiled installation package. When entering PHP – V, an error will be reported: error while loading shared libraries: libonig so.5:cannot open share directory

#php -v
#php: error while loading shared libraries: libonig.so.5:cannot open share directory

Solution:

Step 1

Modify /ECT/LD.so.conf and add the following line:

#vim /etc/ld.so.conf
include ls.so.conf.d/*.conf
/usr/local/lib
/usr/local/x264/lib
/usr/local/openssl/lib
/usr/local/python3.7.1/lib

After saving, execute ldconfig

#ldconfig

Step 2:

Install oniguruma lirary

Download:

https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-devel-6.8.2-1.el7.x86_64.rpm

https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-6.8.2-1.el7.x86_64.rpm

oniguruma-6.8.2-1.el7.x86_64.rpm

oniguruma-devel-6.8.2-1.el7.x86_64.rpm

Use the following commands to install

#rpm -ivh oniguruma-devel-6.8.2-1.el7.x86_64
#rpm -ivh oniguruma-6.8.2-1.el7.x86_64

Then run the command PHP – V to display it perfectly

In case of installation error

Generating autotools files.
./autogen.sh: line 6: autoreconf: command not found

Solution:

[root@yjweb oniguruma-6.9.4]# yum install autoconf automake libtool

[Solved] PHP Error: ErrorException: preg_match(): Compilation failed: invalid range in character class at offset …

One day, the operator came over and said that it was useless to send the verification code by e-mail. As developers, it was our job to solve the problem.

First, check the error log and immediately find that PHP reported an error:

ErrorException: preg_match(): Compilation failed: invalid range in character class at offset 4

The error content means that the regular validation format is wrong and needs to be modified. However, we found no problems in the previous development and use, but recently.

This made us confused until we found that the PHP version of the server was changed from 7.2 to 7.3!

anger

After the difference, we found the cause of the problem:

Upgrade PHP from 7.2 to PHP 7.3

The writing of regular verification format is not standardized

The solution is also simple:

Upgrade the PHP Version (you can not do it, but it is recommended to keep it unified with the server)

Note whether special characters in regular format are escaped. For example, - in [] needs to be escaped: \-

[Solved] WordPress Error: Allowed memory size of 134217728 bytes exhausted

After the website uses Vultr for arrears, it crashes and restarts, and an error occurs:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /www/wwwroot/******.com/wp-content/plugins/header-footer-elementor/inc/class-hfe-settings-page.php on line 422
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32768 bytes) in /www/wwwroot/******.com/wp-content/plugins/wordpress-seo/lib/model.php on line 1

Analysis: After inspection, it is found that the memory size refers to the php cache, which is judged to be a memory overflow problem.

Solution:
1. Modify the background PHP configuration parameter memory_limit 128M to 80M
2. Service>>>Reload configuration>>>Restart>>>Refresh the browser