10

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

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.

PHP.ini

max_execution_time = 300000 
max_input_time = 300000
memory_limit = 256M 

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.

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

9
  • What is the script doing when it stops? Commented Dec 26, 2009 at 22:52
  • 1
    I think at the point it stops, its executing a SQL script using SQLCMD utility. This script is about 500 lines and thats all it does. Every single line is a call to run SQL script using SQLCMD and I am wondering why it fails there since it has done this about 300 hundred times. Nothing in the logs btw too!! :( Commented Dec 26, 2009 at 23:02
  • "Nothing in the logs btw too!" - that includes the logs of the webserver, php and sqlserver? Commented Dec 26, 2009 at 23:04
  • 1
    Yes all of them. The funny thing is, in the "access.log" for Apache. Everything is recorded except the script that keeps timing out. When does Apache make a record of this, after completion of script or before? Commented Dec 26, 2009 at 23:07
  • And how do you execute the sqlcmd utility? Do you use a parameter like -Qto assure sqlcmd quits when it's done? Is it necessary to use sqlcmd? There are php-modules that can communicate with an SQL server "from within" php. Commented Dec 26, 2009 at 23:09

8 Answers 8

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't have php5-xdebug installed but I had the same issue of apach2 segmentation fault(11). May be the cause is different and not just php5-debug.
17.01.2019 Similiar issue here - running Apache2 with PHP 7.3.0 x64 TS over Bitnami, XDebug 2.7.Obetal. Disabling the extension solves the issue.
1

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

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

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

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

Comments

1

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...finally block.

Looks like PHP crashes in this situation:

<?php

function a ()
{
    break;

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

This was with PHP version 5.5.5.

1 Comment

Had exactly the same problem, but caused by another type of "strange" code like 'if ($a[]) $b = $c;'. Once removed it all worked as normal. Seems like the PHP parser sometimes is not recovering from erroneous code.
1

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_flag eaccelerator.enable 0

php_flag eaccelerator.optimizer 0

(or equivalent lines in php.ini):

eaccelerator.enable="0"

eaccelerator.optimizer="0"

Comments

1

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!

Comments

0

I'd try setting all of the error reporting options

-b on error batch abort
-V severitylevel
-m error_level

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();

12 Comments

Thank you for the above, but I think I will leave the above for the last resort because those changes will take me some time to make! I have just confirmed this isn't a PHP problem as the last line of the PHP script is only a notice. The only think left is Apache??
And SQL server (but I don't think this can reset a connection, right?).
Is it really that hard to run this test script? Or at least to copy the existing script, replace exec() by passthru() and add two echo lines? It's only a test.
My use of exec is littered everywhere, this isn't an easy change. Plus, I have SQL Server Management Studio and this should be keeping a record of all errors that occur, so if there are errors I should see it there. Secondly, SQL Server is unlikely to cause the browser to report a connection reset. If anything did happen to SQL server, PHP would know and PHP would report this rather than the browser!! Right?
Btw, I am not refusing your help! :) I am trying it now!
|
0

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() method because 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".

Comments

0

I thought I would add my own experience as well.

I was getting the same error message, which in my case was caused by a PHP error in an exception.

The culprit was a custom exception class that did some logging internally, and a fatal error occurred in that logging mechanism. This caused the exception to not be triggered as expected, and no meaningful message to be displayed either.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.