意外连接重置:是 PHP 还是 Apache 问题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1964554/
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 04:28:33  来源:igfitidea点击:

Unexpected Connection Reset: A PHP or an Apache issue?

apacheconnectionphphttpd.conf

提问by Abs

I have a PHP script that keeps stopping at the same place every time and my browser reports:

我有一个 PHP 脚本,每次都停在同一个地方,我的浏览器报告:

The connection to the server was reset while the page was loading.

在加载页面时重置了与服务器的连接。

I have tested this on Firefox and IE, same thing happens. So, I am guessing this is an Apache/PHP config problem. Here are few things I have set.

我已经在 Firefox 和 IE 上测试过,同样的事情发生了。所以,我猜这是一个 Apache/PHP 配置问题。这是我设置的几件事。

PHP.ini

配置文件

max_execution_time = 300000 
max_input_time = 300000
memory_limit = 256M 

Apache (httpd.conf)

Apache (httpd.conf)

Timeout 300000
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 0

Are the above correct? What can be causing this and what can I set?

以上是否正确?什么可能导致这种情况,我可以设置什么?

I am running PHP (5.2.12.12) as a module on Apache (2.2) on a Windows Server 2003.

我在 Windows Server 2003 上将 PHP (5.2.12.12) 作为模块运行在 Apache (2.2) 上。

It is very likely this is an Apache or PHP issue as all browsers do the same thing. I think the script runs for exactly10 mins (600 seconds).

这很可能是 Apache 或 PHP 问题,因为所有浏览器都做同样的事情。我认为脚本正好运行了10 分钟(600 秒)。

回答by act28

I had a similar issue - turns out apache2 was segfaulting. Cause of the segfault was php5-xdebug for 5.3.2-1ubuntu4.14 on Ubuntu 10.04 LTS. Removing xdebug fixed the problem.

我有一个类似的问题 - 原来 apache2 是段错误。段错误的原因是 Ubuntu 10.04 LTS 上 5.3.2-1ubuntu4.14 的 php5-xdebug。删除 xdebug 解决了这个问题。

回答by gregn3

I also had this problem today, it turned out to be a stray break;statement in the PHP code (outside of any switch or any loop), in a function with a try...catch...finallyblock.

我今天也遇到了这个问题,原来break;是 PHP 代码中的一个杂散语句(在任何开关或任何循环之外),在一个带有try...catch...finally块的函数中。

Looks like PHP crashes in this situation:

看起来 PHP 在这种情况下会崩溃:

<?php

function a ()
{
    break;

    try
    {
    }
    catch (Exception $e)
    {
    }
    finally
    {
    }
}

This was with PHP version 5.5.5.

这是 PHP 5.5.5 版。

回答by Gavin G

I had an issue where in certain cases PHP 5.4 + eAccelerator = connection reset. There was no error output in any log files, and it only happened on certain URLs, which made it difficult to diagnose. Turns out it only happened for certain PHP code / certain PHP files, and was due to some incompatibilities with specific PHP code and eAccelerator. Easiest solution was to disable eAccelerator for that specific site, by adding the following to .htaccess file

我遇到了一个问题,在某些情况下 PHP 5.4 + eAccelerator = 连接重置。任何日志文件中都没有错误输出,并且只发生在某些 URL 上,这使得诊断变得困难。原来它只发生在某些 PHP 代码/某些 PHP 文件中,并且是由于与特定 PHP 代码和 eAccelerator 的某些不兼容。最简单的解决方案是禁用该特定站点的 eAccelerator,方法是将以下内容添加到 .htaccess 文件

php_flag eaccelerator.enable 0

php_flag eaccelerator.enable 0

php_flag eaccelerator.optimizer 0

php_flag eaccelerator.optimizer 0

(or equivalent lines in php.ini):

(或 php.ini 中的等效行):

eaccelerator.enable="0"

eaccelerator.enable="0"

eaccelerator.optimizer="0"

eaccelerator.optimizer="0"

回答by Diego Sagrera

It's an old post, I know, but since I couldn't find the solution to my problem anywhere and I've fixed it, I'll share my experience. The main cause of my problem was a file_exists()function call.
The file actually existed, but for some reason an extra forward slash on the file location ("//") that normally works on a regular browser, seems not to work in PHP. Maybe your problem is related to something similar. Hope this helps someone!

这是一个旧帖子,我知道,但由于我无法在任何地方找到我的问题的解决方案并且我已经修复了它,我将分享我的经验。我的问题的主要原因是file_exists()函数调用。
该文件实际上存在,但由于某种原因,通常在常规浏览器上工作的文件位置(“//”)上的额外正斜杠在 PHP 中似乎不起作用。也许您的问题与类似的事情有关。希望这可以帮助某人!

回答by Tonio

Differences between 2 PHP configs were indeed the root cause of the issue on my end. My app is based on the NuSOAP library.

2 个 PHP 配置之间的差异确实是我最终出现问题的根本原因。我的应用程序基于 NuSOAP 库。

On config 1 with PHP 5.2, it was running fine as PHP's SOAP extension was off.

在使用 PHP 5.2 的配置 1 上,它运行良好,因为 PHP 的 SOAP 扩展已关闭。

On config 2 with PHP 5.3, it was giving "Connection Reset" errors as PHP's SOAP extension was on.

在使用 PHP 5.3 的配置 2 上,当 PHP 的 SOAP 扩展打开时,它会给出“连接重置”错误。

Switching the extension off allowed to get my app running on PHP 5.3 without having to rewrite everything.

关闭扩展允许让我的应用程序在 PHP 5.3 上运行,而无需重写所有内容。

回答by Slawa

My PHP was segfaulting without any additional information as to the cause of it as well. It turned out to be two classes calling each other's magic __call() methodbecause both of them didn't have the method being called. PHP just loops until it's out of memory. But it didn't report the usual "Allowed memory size of * bytes exhausted" message, probably because the methods are "magic".

我的 PHP 出现了段错误,但没有任何关于其原因的额外信息。原来是两个类在调用彼此的魔法 __call() 方法,因为它们都没有被调用的方法。PHP 只是循环,直到内存不足。但它没有报告通常的“*字节用尽的允许内存大小”消息,可能是因为这些方法是“神奇的”。

回答by VolkerK

I'd try setting all of the error reporting options

我会尝试设置所有错误报告选项

-b on error batch abort
-V severitylevel
-m error_level
-b 错误批处理中止
-V 严重级别
-m错误级别

and sending all the output to the client

并将所有输出发送到客户端

<?php
echo "<div>starting sql batch</div>\n<pre>"; flush();
passthru('sqlcmd -b -m -1 -V 11 -l 3 -E -S TYHSY-01 -d newtest201 -i "E:\PHP_N\M_Create_Log_SP.sql"');
echo '</pre>done.'; flush();