使用 PHP 读取文件出现 500 错误

发布于 2024-12-17 11:21:44 字数 174 浏览 2 评论 0原文

我有一个使用 readfile() 读取 mp3 文件的脚本(我也尝试过使用循环的 fread() )。在一个特定文件上我收到 500 错误。所有其他文件似乎都读得很好。

当我查看服务器上的错误日志时,我注意到每当尝试读取此特定文件时都会出现 PHP 内存错误。

谁能给我一些关于可能发生的事情的指示?

I have a script which reads a mp3 file with readfile() (I have also tried fread() with a loop). And on one particular file I am getting a 500 error. All other files seem to read just fine.

When I review the error log on my server I notice I am getting a PHP memory error when ever this particular file is attempted to be read.

Can anyone give me some pointers as to what might be going on?

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

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

发布评论

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

评论(5

鸢与 2024-12-24 11:21:44

您已经指出了问题 - PHP 内存不足。 PHP 中的最大内存使用量受 ini 设置限制。

您可以在运行时在脚本顶部使用 ini_set 设置它:

ini_set('memory_limit', '64M');

或者您可以在 php.ini 文件中设置它,以便它在 < em>所有脚本:

memory_limit = 64M;

最后可以看到使用的内存当前正在执行的脚本,带有 memory_get_usage( )

You already pointed out the problem - PHP is running out of memory. Maximum memory usage in PHP is limited by an ini setting.

You can set it at runtime at the top of your script with ini_set:

ini_set('memory_limit', '64M');

Or you can set it in your php.ini file so it takes effect for all scripts:

memory_limit = 64M;

Finally, you can see the memory used by the currently executing script with memory_get_usage()

久隐师 2024-12-24 11:21:44

mp3 文件的文件大小大于 memory_limit。如果您想从此 mp3 文件中读取数据,则需要增加 PHP 可以访问的内存量。

如果您有权访问 php.ini 文件,则可以找到 memory_limit = 16M ; 并将该值替换为您需要的内存量。

如果您没有 php.ini 访问权限,但有 .htaccess 访问权限,请添加:

php_value memory_limit 16M

并替换该值。

如果两者都没有,请尝试压缩 mp3 文件或以其他方式减少执行此操作所需的内存量。尝试清除未使用且占用大量内存的变量。

The mp3 file is of a larger filesize than memory_limit. You'll need to increase the amount of memory PHP can access if you want to read from this mp3 file.

If you have access to the php.ini file, you can find memory_limit = 16M ; and replace the value with however much memory you need.

If you don't have php.ini access and you do have .htaccess access, add:

php_value memory_limit 16M

and replace the value.

If you have neither, try compressing the mp3 file or otherwise reducing the amount of memory it will take for you to perform this action. Try clearing variables which are unused and take up large amounts of memory.

煞人兵器 2024-12-24 11:21:44

好吧,在完成脚本之前 php 可能已经耗尽内存了。您可以通过更改 php.ini 中的 memory_limit 选项来增加允许 php 运行的内存。

Well, php is probably running out of memory before completing the script. You can just increase the memory php is allowed to run by changing the memory_limit option in your php.ini.

万水千山粽是情ミ 2024-12-24 11:21:44

尝试增加执行时间:
设置时间限制(300); //300秒
ini_set('内存限制'​​,'16M'); //增加到某个值,例如 16 MB

Try increasing the execution time:
set_time_limit(300); //300 seconds
ini_set('memory_limit','16M'); //increase to some value like 16 MB

猫卆 2024-12-24 11:21:44

它很可能超出最大内存。这可以在 php.ini 中进行调整,请检查此处: http://www.php.net/manual/en/ini.core.php#ini.memory-limit

Most likely it exceeds maximum memory. This can be adjusted in the php.ini, check here: http://www.php.net/manual/en/ini.core.php#ini.memory-limit

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