警告:gzdecode():php 中的数据错误


Warning: gzdecode(): data error in php

我知道这个问题已经问过了,但我无法解决我的问题,所以我在这里解释了我的问题,请帮助我解决这个问题。

我正在使用 file_get_contens() 从此示例 URL 获取数据

$URL1 = 'abcd.com/xxx';
$URL2 = 'abcd.com/yyy';
$URL3 = 'abcd.com/zzz';
$response1 = file_get_contents($URL1);
$response2 = file_get_contents($URL2);
$response3 = file_get_contents($URL3);

我使用 gzencode 压缩响应数据,因为数据太长并添加了前缀供我参考然后我将压缩数据保存到数据库

$arrayResponse['URL1'] = '_|_coMpResSed_|_' . gzencode($response1);
$arrayResponse['URL2'] = '_|_coMpResSed_|_' . gzencode($response2);
$arrayResponse['URL3'] = '_|_coMpResSed_|_' . gzencode($response3);

数据库详细信息

  • 存储引擎 : InnoDB
  • 排序规则 : utf8mb4_unicode_ci
  • 类型:长斑点或长文本(我都试过)

我使用 gzdecode 解压缩数据

$temp1 = explode('_|_coMpResSed_|_', $arrayResponse['URL1']);
$temp2 = explode('_|_coMpResSed_|_', $arrayResponse['URL2']);
$temp3 = explode('_|_coMpResSed_|_', $arrayResponse['URL3']);
if (!empty($temp1[1]) && !empty($temp2[1]) && !empty($temp3[1])) {
    $arrayResponse['URL1'] = gzdecode($temp1[1]);//working fine 
    $arrayResponse['URL2'] = gzdecode($temp2[1]);// getting warning 
    $arrayResponse['URL3'] = gzdecode($temp3[1]);//working fine     
}

我收到"警告:

gzdecode(): data error on line $arrayResponse['URL2'] = gzdecode($temp 2[1]);'

其他线路工作正常。我不知道我在哪里犯了错误。谁能帮我得到这个?

遇到同样的问题,我只是看了一下Mysql文档:https://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html

许多加密和压缩函数返回结果可能包含任意字节值的字符串。如果要存储这些结果,请使用具有 VARBINARYBLOB 二进制字符串数据类型的列。这将避免尾随空格删除或字符集转换时发生的潜在问题,这些问题会更改数据值,例如在使用非二进制字符串数据类型(CHAR、VARCHAR、TEXT)时可能会发生的问题。

我只是将列数据类型更改为 VARBINARY,一切正常。