php 500 服务器错误:脚本头过早结束:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4336757/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 12:43:28  来源:igfitidea点击:

500 Server error: Premature end of script headers:

phpapachecodeigniter

提问by Stéphane Goetz

I have a website in php that works with a solr indexation server, based on CodeIgniter.

我有一个 php 网站,它与基于 CodeIgniter 的 solr 索引服务器一起使用。

We got a lot of new content, so we flushed the database, and had to reindex the content (about 168,000 elements). I created a script to index the contents by slices of 500 – when the script finishes, we launch the next indexing.

我们得到了很多新内容,所以我们刷新了数据库,并且不得不重新索引内容(大约 168,000 个元素)。我创建了一个脚本来按 500 的切片索引内容——当脚本完成时,我们启动下一个索引。

It works perfectly on my local test environment, but on production I get this 500 error:

它在我的本地测试环境中完美运行,但在生产中我收到了这个 500 错误:

[Thu Dec 02 ...] [error] [client IP] Premature end of script headers: index.php

There is absolutely nothing in my php.log, just the apache error_log that returns it. I've seen it happen on other pages of the website once or twice, but it was during this indexing.

我的 php.log 中绝对没有任何内容,只有返回它的 apache error_log。我曾在网站的其他页面上看到它发生过一两次,但它是在编制索引期间发生的。

Any ideas?

有任何想法吗?

回答by Fabrizio D'Ammassa

This error is usually (sometimes) caused by the FastCGI setup of the FcgidIOTimeoutdirective(old name: IPCCommTimeout).

此错误通常(有时)由FcgidIOTimeout指令(旧名称:)的 FastCGI 设置引起IPCCommTimeout

That is the number of seconds for IO timeout, default is 40 seconds. Timeout means that

即 IO 超时的秒数,默认为 40 秒。超时意味着

"The FastCGI application must begin generating the response within this period of time. Increase this directive as necessary to handle applications which take a relatively long period of time to respond."

“FastCGI 应用程序必须在这段时间内开始生成响应。根据需要增加此指令以处理需要相对较长时间响应的应用程序。”

You can try to solve it putting this into your vhost.conf:

您可以尝试将其放入 vhost.conf 来解决它:

<IfModule mod_fcgid.c>
  # 5 minutes for IO timeout, default is 40 seconds
  FcgidIOTimeout 300
</IfModule>

You can increase it as you need and then restore the original value once the reindexing process is complete.

您可以根据需要增加它,然后在重新索引过程完成后恢复原始值。

回答by Tim

There is a good list about the possibilities on Liquid Web's KB;

在 Liquid Web 的 KB 上有一个关于可能性的很好的列表;

  1. Upgrading or downgrading to a different version of PHP can leave residual options in the httpd.conf. Check the current version of PHP using php -v on the command line and search for any lines mentioning another version in the httpd.conf. If you find them, comment them out, distill the httpd.conf and restart apache.

  2. The RLimitCPU and RLimitMEM directives in the httpd.conf may also be responsible for the error if a script was killed due to a resource limit.

  3. A configuration problem in suEXEC, mod_perl, or another third party module can often interfere with the execution of scripts and cause the error. If these are the cause, additional information relating to specifics will be found in the apache error_log.

  4. If suphp's log reaches 2GB in size or larger you may see the premature end of scripts headers error. See what the log contains and either gzip it or null it. Restart apache and then deal with any issues that the suphp log brought to light. The suphp log is located at: /usr/local/apache/logs/suphp_log

  5. The script's permissions may also cause this error. CGI scripts can only access resources allowed for the User and Group specified in the httpd.conf. In this case, the error may simply be pointing out that an unauthorized user is attempting to access a script.

  1. 升级或降级到不同版本的 PHP 可能会在 httpd.conf 中留下剩余选项。在命令行上使用 php -v 检查 PHP 的当前版本,并在 httpd.conf 中搜索任何提及另一个版本的行。如果找到它们,将它们注释掉,提取 httpd.conf 并重新启动 apache。

  2. 如果脚本由于资源限制而被终止,则 httpd.conf 中的 RLimitCPU 和 RLimitMEM 指令也可能导致错误。

  3. suEXEC、mod_perl 或其他第三方模块中的配置问题通常会干扰脚本的执行并导致错误。如果这些是原因,将在 apache error_log 中找到与细节相关的其他信息。

  4. 如果 suphp 的日志大小达到 2GB 或更大,您可能会看到脚本标题错误的过早结束。查看日志包含的内容并对其进行 gzip 或 null。重新启动 apache,然后处理 suphp 日志带来的任何问题。suphp 日志位于:/usr/local/apache/logs/suphp_log

  5. 脚本的权限也可能导致此错误。CGI 脚本只能访问 httpd.conf 中指定的用户和组允许的资源。在这种情况下,错误可能只是指出未经授权的用户正在尝试访问脚本。

http://www.liquidweb.com/kb/apache-error-premature-end-of-script-headers/

http://www.liquidweb.com/kb/apache-error-premature-end-of-script-headers/

If I were in the same situation, I'd check the permissions first then continue with 3 and 4.

如果我处于相同的情况,我会先检查权限,然后继续 3 和 4。

回答by the.s.brom

I was also receiving this error message in etc/httpd/logs/error_log after a 500 Internal server error trying to load a website.

在尝试加载网站时出现 500 内部服务器错误后,我还在 etc/httpd/logs/error_log 中收到此错误消息。

For me, the solution was permissions - had to chmod 755 the file. I had created the file as a higher access level user than the one that was "loading" the site on the server.

对我来说,解决方案是权限 - 必须 chmod 755 文件。我以比在服务器上“加载”站点的用户更高的访问级别用户身份创建了该文件。

回答by Jacob Arlington

its also can because of using PHP APC Extension in a wrong way. so first remove apc.so from php.ini restart apache and test it again :)

它也可能因为以错误的方式使用 PHP APC 扩展。所以首先从 php.ini 中删除 apc.so 重新启动 apache 并再次测试:)

回答by Youssef K. Yassin

I had this problem and after struggling for more than 5 hours, I disabled xcache and everything went back to normal, error disappeared!

我遇到了这个问题,在挣扎了 5 个多小时后,我禁用了 xcache,一切恢复正常,错误消失了!

回答by Dr.Molle

What's your error_level in php? The error-message you get there inside the log is often result of a simple PHP-error, but the server is setup to do not deliver error-messages to the client for security-reasons. By this the message is not very helpful, it could be everything.

你在 php 中的 error_level 是多少?您在日志中获得的错误消息通常是简单的 PHP 错误的结果,但出于安全原因,服务器设置为不向客户端发送错误消息。通过这一点,消息不是很有帮助,它可能是一切。

回答by HimalayanCoder

u forgot to add content-type header in the response which is a must have http header when hosting on apache2

您忘记在响应中添加内容类型标头,这是在 apache2 上托管时必须具有的 http 标头

header('Content-Type: text/html');

回答by 23Pstars

I had the same problem, just restart the apache server and it works

我遇到了同样的问题,只需重新启动 apache 服务器即可