ERR_CONNECTION_RESET with PHP script

蹲街弑〆低调 提交于 2019-12-13 19:19:03

问题


I have a PHP scripts that downloads and process some files. Sometimes the number of files is very large, so it takes some time.

But when there are a lot of files to process, the connection interrupts with a "ERR_CONNECTION_RESET" error (Chrome).

Here's my configuration:

upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 0
max_input_time = -1
memory_limit = 512M

I have a shared hostind. Anyone knows how to fix this?


回答1:


If there are too many files to process, you'll eventually stumble upon this issue whatever your configuration. Even if you disable all timeouts server-side, the client itself has its own safety features and will eventually timeout after a certain time — something you can't control.

You are doing it wrong” here. You cannot do any heavy computation in a HTTP request because of this kind of protocol limitations (TCP, HTTP).

Your request has to spawn some kind of background task that will notify of its progress from time to time. Using a shared hosting with PHP only, this might not be easy to accomplish, so you may want to find another way of doing your heavy computation.




回答2:


ERR_CONNECTION_RESET usually means that the connection to the server has died without any responses to the client – not even some kind of HTTP 5xx error. This means that the entire PHP process has died without being able to shut down properly.

This is usually not caused by something like an exceeded memory_limit, because that's something PHP would handle gracefully. This must be some sort of Segmentation Fault or similar. If you have access to error logs, check them. Otherwise, you might get support from your hosting company.




回答3:


I actually stumbled across this problem doing a very similair thing, my problem (in case it helps anyone) was that I was creating an Object every time I called my function, ie:

function myFunction($param) {
    ...
    // Create an object
    $obj = new MyObject();
    ...
}

I simply changed it too:

function myFunction($param, $obj) {
    ...
    //Do stuff with $obj
    ...
}

// Create an object
$obj = new MyObject();
// Call Function
$myresult = myFunction($params, $obj);

Noob I know but hope this helps someone else.




回答4:


Cleaning cookies resolved it when I had this issue on Google chrome




回答5:


On my IIS server with ASP.NET MVC, I accidentially generated the ERR_CONNECTION_RESET error in Google Chrome due to the fact that my HTTP status code description contained new line characters (\r\n).

I. e. this would generate the error:

public ActionResult Index()
{
    Response.StatusCode = 200;
    Response.StatusDescription = "This is a status code\r\nwith newline.";

    return View();
}

To resolve it, I simply removed the newline characters.

Another issue may be that the status code description is too long.



来源:https://stackoverflow.com/questions/25378703/err-connection-reset-with-php-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!