PHP 导入脚本中出现未初始化的字符串偏移错误
我有一个从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这里解决:
http://www.phpbuilder.com/board/archive/ index.php/t-10328608.html
Solved here:
http://www.phpbuilder.com/board/archive/index.php/t-10328608.html
...表示
$data
不是数组。... means that
$data
is not an array.感谢您的输入,通过我找到我正在使用的解析库的更新版本,情况已经“自行解决”。 我的猜测是这个问题与 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.