PHP解包溢出变量内存限制

PHP unpack overlfow variable memory limit

我目前尝试以 hex 格式回显 DLL 文件的原始字节,解包函数溢出变量内存限制(我的托管服务 atm 无法设置),是否有任何方法可以将其按部分读入 3或更多变量,或其他输出字节并回显这些字节的方法?

文件大小约为 1.98MB(1.990.656 字节)(是的,我知道 php 中的缓冲区要大得多)。

发生以下错误: 致命错误:允许的 67108864 字节内存已用尽(已尝试分配 67108872 字节)

感谢您的帮助。

ini_set('memory_limit', '-1');
$fileName= "driver.dll"; 
$fsize = filesize($fileName); 

$hex = unpack("C*", file_get_contents($fileName));
$hexa_string= "";

foreach($hex as $v) 
{
    $hexa_string.= sprintf("%02X", $v);
}

echo $hexa_string;

您必须使用 c 包装程序进行文件操作:fseek

$size = 1024 * 1000;
$handle = fopen($file, 'r');
fseek($handle, -$size);
$limitedContent = fread($handle, $size);