How to solve the problem of zabbix monitoring causing Chinese garbled characters in the graphical interface due to PHP problems

How to solve the problem of zabbix monitoring causing Chinese garbled characters in the graphical interface due to PHP problems

Solve the problem of Chinese garbled characters in the graphical interface of Zabbix monitoring system caused by adding the -enable-gd-jis-conv option in compiling PHP

Phenomenon:

PHP compilation parameters:

illustrate:

If PHP is compiled with the --enable-gd-jis-conv option enabled, non-ASCII characters (such as Chinese characters, Pinyin, Greek and arrows) will be treated as EUC-JP characters (called "JIS-encoded fonts" in phpinfo), resulting in garbled characters (since Western fonts have no kana or Chinese characters, they are generally displayed as all boxes). The imagettftext() function is used to write characters into a picture. This problem is caused by this function.

I have checked several incomplete tutorials on the Internet. The following is my production practice operation, in zabbix3.2 version, php7.2 version

Method 1:

Recompile and install PHP, disabling the -enable-gd-jis-conv option. This method is more expensive.

Method 2:

Because the production environment PHP has been used for a long time, I don't know if there are any applications using it, so I dare not recompile it easily, so I solve it according to method 2

first step:

Modify the graphs.inc.php file in /etc/nginx/html/zabbix/include (back up first)

cp graphs.inc.php graphs.inc.php.bak

vim graphs.inc.php #在末尾添加如下代碼

function to_entities($string){
 $len = strlen($string);
 $buf = "";
 for($i = 0; $i < $len; $i++){
  if (ord($string[$i]) <= 127){
   $buf .= $string[$i];
  } else if (ord ($string[$i]) < 192) {
   //unexpected 2nd, 3rd or 4th byte
   $buf .= "?";
  } else if (ord ($string[$i]) < 224) {
   //first byte of 2-byte seq
   $buf .= sprintf("&#%d;",
    ((ord($string[$i + 0]) & 31) << 6) +
    (ord($string[$i + 1]) & 63)
   );
   $i += 1;
  } else if (ord ($string[$i]) < 240) {
   //first byte of 3-byte seq
   $buf .= sprintf("&#%d;",
    ((ord($string[$i + 0]) & 15) << 12) +
    ((ord($string[$i + 1]) & 63) << 6) +
    (ord($string[$i + 2]) & 63)
   );
   $i += 2;
  } else {
   //first byte of 4-byte seq
   $buf .= sprintf("&#%d;",
    ((ord($string[$i + 0]) & 7) << 18) +
    ((ord($string[$i + 1]) & 63) << 12) +
    ((ord($string[$i + 2]) & 63) << 6) +
    (ord($string[$i + 3]) & 63)
   );
   $i += 3;
  }
 }
 return $buf;
}

Step 2:

Find the imagettftext() function in the file (three places in total)

Change the last parameter $string to to_entities($string) . All three places need to be modified. No need to restart, just refresh to solve the problem.

Summarize

The above is the method I introduced to you to solve the problem of garbled Chinese characters in the graphical interface of Zabbix monitoring due to PHP problems. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Solution to the garbled Chinese file name problem in PHP fopen
  • PHP reads files and analyzes the method of solving Chinese garbled UTF-8
  • Solution to PHP's garbled text output
  • Example solution for writing garbled Chinese characters into MySQL in PHP
  • Solution to PHP writing txt garbled code
  • Solve the problem of PHP writing garbled characters into the database
  • Solution to garbled characters when sending push messages in PHP WeChat
  • PHP solves the problem of garbled Chinese output

<<:  How to capture exceptions gracefully in React

>>:  Optimize the storage efficiency of BLOB and TEXT columns in InnoDB tables

Recommend

Summary of HTML knowledge points for the front end (recommended)

1. HTML Overview htyper text markup language Hype...

The role of nextTick in Vue and several simple usage scenarios

Purpose Understand the role of nextTick and sever...

Comparative Analysis of IN and Exists in MySQL Statements

Background Recently, when writing SQL statements,...

Nginx installation error solution

1. Unzip nginx-1.8.1.tar.gz 2. Unzip fastdfs-ngin...

Problems encountered when updating the auto-increment primary key id in Mysql

Table of contents Why update the auto-increment i...

JavaScript basics for loop and array

Table of contents Loop - for Basic use of for loo...

Linux five-step build kernel tree

Table of contents 0. The kernel tree that comes w...

Summary of how JS operates on pages inside and outside Iframe

Table of contents Get the content of the iframe o...

How to install and configure MySQL and change the root password

1. Installation apt-get install mysql-server requ...

MySQL and MySQL Workbench Installation Tutorial under Ubuntu

Ubuntu install jdk: [link] Install Eclipse on Ubu...

Vue detailed explanation of mixins usage

Table of contents Preface 1. What are Mixins? 2. ...

Pessimistic locking and optimistic locking in MySQL

In relational databases, pessimistic locking and ...