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).

Abs
  • 56,052
  • 101
  • 275
  • 409
  • What is the script doing when it stops? – cletus Dec 26 '09 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!! :( – Abs Dec 26 '09 at 23:02
  • "Nothing in the logs btw too!" - that includes the logs of the webserver, php and sqlserver? – VolkerK Dec 26 '09 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? – Abs Dec 26 '09 at 23:07
  • And how do you execute the sqlcmd utility? Do you use a parameter like `-Q`to 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. – VolkerK Dec 26 '09 at 23:09
  • Don't worry, I do know that its not a good idea to use SQLCMD - will soon be switching to the PHP Driver by MS. I execute SQLCMD using exec , this is an example: sqlcmd -E -S TYHSY-01 -d newtest201 -i "E:\PHP_N\M_Create_Log_SP.sql" – Abs Dec 26 '09 at 23:11
  • And do you use passthru() or the `-o xyz.log` option to catch messages from sqlcmd? – VolkerK Dec 26 '09 at 23:38
  • I only use exec() to execute those commands and I log the output to a textfile. The log file shows all execution were successful and I have doubled checked in SQL Server and have confirmed the changes. – Abs Dec 26 '09 at 23:39
  • Have you checked your php error log (the `error_log` in `php.ini`)? Apache logs after request completion since it needs to log the HTTP status code and the content length. – Kenney Sep 21 '15 at 14:26

8 Answers8

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.

act28
  • 31
  • 2
  • 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. – Bhargav Nanekalva Jul 03 '13 at 11:04
  • 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. – Leon Willens Jan 17 '19 at 08:42
2

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.

gregn3
  • 1,728
  • 2
  • 19
  • 27
  • 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. – karpy47 May 13 '16 at 13:57
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"

Gavin G
  • 856
  • 6
  • 6
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!

Diego Sagrera
  • 263
  • 5
  • 11
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.

Tonio
  • 11
  • 1
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".

Slawa
  • 1,141
  • 15
  • 21
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();
VolkerK
  • 95,432
  • 20
  • 163
  • 226
  • 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?? – Abs Dec 27 '09 at 00:01
  • And SQL server (but I don't think this can reset a connection, right?). – Abs Dec 27 '09 at 00:02
  • 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. – VolkerK Dec 27 '09 at 00:08
  • 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? – Abs Dec 27 '09 at 00:20
  • Btw, I am not refusing your help! :) I am trying it now! – Abs Dec 27 '09 at 00:47
  • Just tried this, but the above didn't even work for me. I get a straight, login denied for NT-Authority/System?? – Abs Dec 27 '09 at 01:02
  • That's because you let the apache process run as "localsystem" (+ php as module/no impersonation). The new process spawned by passthru() inherits the account/security token. But that would also apply to exec(). Do you use the exact same command string except the -b/-m/-V option? Try it without the `-l 3`connection timeout option (though I doubt that the cause) – VolkerK Dec 27 '09 at 01:14
  • Yes, I use that same exact command. I will try it without "-l". Yes, PHP will run as an Apache process and this hasn't caused any problems when using the exec function. – Abs Dec 27 '09 at 01:23
  • The same thing happens :( - but why do you think its a SQL Server problem? What makes you think this, I would really like to now. – Abs Dec 27 '09 at 01:45
  • I don't think it's an SQLserver problem (I thought sqlcmd doesn't exit under certain conditions and passthru() will show you something like "press enter to continue") . Right now it seems to be an authentication problem. When a process runs as localsystem the integrated authentication uses the machine's credentials and not a specific user account (same as if you try to establish a smb network connection). The difference between exec() and passthru() at this point eludes me ;-) When you replace passthru() by exec() again in the test script your sql batch is executed? – VolkerK Dec 27 '09 at 12:12
  • No, I just get straight access denied error even after removing "-l". What if it returned "press enter to continue"? What does that mean? Does it mean SQLCMD doesn't exist and PHP is just waiting for nothing and therefore timesout?? – Abs Dec 27 '09 at 20:30
  • yes, that was the general idea. sqlcmd waiting for some input, php waiting for sqlcmd to exit, timeout, the end. The failing authentication is a different story. – VolkerK Dec 28 '09 at 04:30
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.

AeonOfTime
  • 956
  • 7
  • 10