PHP 导入脚本中出现未初始化的字符串偏移错误

发布于 2024-07-08 01:57:55 字数 925 浏览 12 评论 0原文

我有一个从 excel 导入脚本作为 CMS 的一部分,之前运行没有问题。

我的共享托管提供商最近升级了他们的基础设施,包括 PHP 从 5.1 到 5.2.6,脚本现在返回“未初始化的字符串偏移量:第 27 行 /path/scriptname.php 中的 -XXX”(XXX 是从512 和 /path/scriptname.php 当然是相关脚本的完整路径)。

它会为 Excel 文件的每一行返回此错误。 第 27 行只是函数内的返回,该函数是处理导入数据的第一个点:

function GetInt4d($data, $pos) {
        return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24); 
}

它最终因“致命错误:/path 中允许的内存大小 47185920 字节耗尽(尝试分配 71 字节)而崩溃” /scriptname.php 第 133 行”。

Apache 错误日志中没有任何有用的信息。 我很困惑。 有人知道至少去哪里看吗? 即使知道它是否可能是我的脚本中的某些内容或与升级有关的内容也会很有用。 我在同一提供商的不同站点上遇到了另一个问题,该问题(升级后)无法将会话写入 tmp 目录(已解决),但我很确定不是那样(?)。

编辑:事实证明,答案与解析器的版本在某种程度上与 PHP 5.2.6 不兼容有关,我认为有问题的解析器可能对某人有用 电子表格 Excel 阅读器

I have an import-from-excel script as part of a CMS that previously ran without issue.

My shared-hosting provider has recently upgraded their infrastructure, including PHP from 5.1 to 5.2.6, and the script now returns "Uninitialized string offset: -XXX in /path/scriptname.php on line 27" (XXX being a decreasing number from 512 and /path/scriptname.php of course being the full path to script in question).

It returns this error for every line of the excel file. Line 27 is just a return from within a function that is the first point at which the imported data is being processed:

function GetInt4d($data, $pos) {
        return ord($data[$pos]) | (ord($data[$pos+1]) << 8) | (ord($data[$pos+2]) << 16) | (ord($data[$pos+3]) << 24); 
}

It finally implodes with a "Fatal error: Allowed memory size of 47185920 bytes exhausted (tried to allocate 71 bytes) in /path/scriptname.php on line 133".

There's nothing useful in Apache error logs. I am stumped. Anyone have any ideas of at least where to look? Even knowing if it's likely to be something within my script or something to do with upgrade would be useful. I had another issue with a different site on same provider that (after upgrade) couldn't write sessions to tmp directory (since resolved), but am pretty sure it's not that (?).

EDIT: As it turned out that the answer was to do with the version of the parser being incompatible in some way with PHP 5.2.6, I thought it might be of use to someone that the parser in question is Spreadsheet Excel Reader .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

流星番茄 2024-07-15 01:57:55

未初始化的字符串偏移量:

...表示 $data 不是数组。

Uninitialized string offset:

... means that $data is not an array.

—━☆沉默づ 2024-07-15 01:57:55

感谢您的输入,通过我找到我正在使用的解析库的更新版本,情况已经“自行解决”。 我的猜测是这个问题与 php 版本之间的差异有关,尽管我不确定到底是什么。 已修复但令人沮丧。

编辑:我将接受蒂尔的回答纯粹是为了结束问题。 再次感谢您的输入。

Thanks for the input, the situation has 'resolved itself' via me finding a more recent version of the parsing library I was using. My guess is the issue was something to do with the difference between php versions, though I'm unsure exactly what. Fixed but frustrating.

EDIT: I'm going to accept Till's answer purely in the interests of closing the question. Thx again for input.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文