tags:

views:

184

answers:

10

I have a PHP webpage, that generates statistics and takes about 15sec to generate them, before sending them to the Browser.

The issue I have is that the browser ends up loading with a blank page. Unfortunately I don't have access to the error_log file.

But I figured, that if I start sending data in the foreach-loop which consumes most of the generation time like so

echo ' ';

the connection will not terminate and the page will load.

First I thought this might be a memory_limit or max_execution_time issue, so I increased both, without any luck. But this would also seam odd to me since hitting the max_execution_time would result in a blank page no matter I'm sending echo ' ' or not.

Is there an other PHP setting, I don't know of, that would cause a connection to terminate after about 10sec without data beeing send?

Edit:

The page is not completely blank. Here is the data beeing sent:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html>
<head>
  <meta name="author" content="Gerd Grützmacher">
  <meta name="robots" content="index,follow">
  <meta http-equiv="Language" content="de">  
  <link rel="icon" href="/favicon.png" type="image/png">

  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;

  <!--[if (gte IE 5.9)]><!-->
  <link rel="stylesheet" type="text/css" href="css/gruppenunterkuenfte-min.css" />
  <!--<![endif]-->

  <!--[if IE 6]>
  <style type="text/css" media="screen, projection">
       @import url(css/ie6.css);
  </style>
  <![endif]-->

  <!--[if gte IE 5.9]><!-->
    <script type="text/javascript" src="scripts.js"></script>
  <!--<![endif]-->

After this point the statistics are beeing generated and therefore I only see a blank page.

Here is the HTTP-Header:

quest URL:http://dev.gruppenunterkuenfte.de/index.php?mod=home&amp;action=stats_belegungsanfrage2
Request Method:GET
Status Code:200 OK
Request Headers
Accept:application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Cache-Control:max-age=0
Referer:http://dev.gruppenunterkuenfte.de/index.php?mod=home&amp;action=stats_belegungsanfrage2
User-Agent:Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3
Query String Parameters
mod:home
action:stats_belegungsanfrage2
Response Headers
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:close
Content-Type:text/html; charset=utf-8
Date:Sat, 25 Sep 2010 15:07:11 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Pragma:no-cache
Server:Apache/2.2.16
Transfer-Encoding:chunked
X-Powered-By:PHP/5.2.11

Here you can see the output of phpinfo():

http://dev.gruppenunterkuenfte.de/info.php

+1  A: 

Based on the info so far, I'm thinking that the browser may be timing out the connection due to inactivity.

When you output the delayed single char (' ' in your case) try putting a flush() call after it to try and flush the buffer through the network and hopefully generate some activity. If this doesn't work, perhaps try sending a larger string; you may need to fill the output buffer before it will flush at all.

jay.lee
flush() does not help. I guess because the output buffer is empty anyway, if I don't do any echos.
JochenJung
@JochenJung: then do echo something. I agree with jay.lee, it may be the fact that the browser times out because there is no answer from the server. Also try different browsers, since they have different behavior.
MainMa
Both Chrome and Firefox stop loading after 10sec.
JochenJung
@JochenJung @MainMa It may be Apache that's closing the connection, rather than PHP. Perhaps it's a setting in `apache.conf`?
mattbasta
Most browsers will display a "Server took too long to respond" message. So if something is timing out, I don't think it's the browser.
mellowsoon
A: 

Not sure how your code is laid out, but if you are looping through any results to display them, try echoing them each loop, or echo something each loop.

Without seeing code, hard to tell.

Patrick
No, I need to calculate stuff within the loop and have the results not before finishing the loop.
JochenJung
A: 

Check that an error is not occurring by enabled error reporting before you do anything:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
Petah
I just set both in the php.ini file. But it does not bring up more errors. The page just stops loading after some secs.
JochenJung
If you don't see any error messages, then there's no timeout (since that would generate a fatal error) and it MUST be an error in your code. So either provide relevant snippets or debug your script with xdebug/Zend Debugger from within your IDE of choice.
wimvds
Try putting a blatantly obvious bit of errored code in some where and see if that causes an error.
Petah
Yes, I can produce errors and they are correctly displayed on the page.
JochenJung
If apache causes the timeout, would that also be an entry in the error_log?
JochenJung
A: 

Unfortunately I don't have access to the error_log file.

Errr... Why don't you point error_log to a file/location you have access to? Just set it at the start of your script using ini_set, ie.

ini_set('log_errors', 1);
ini_set('error_log', '/path/to/yourlog.log');

You could also change the value of error_reporting as you see fit.

wimvds
Error_log is working now (see comments beneath my question). But still no new lines in them.
JochenJung
A: 

Hi,

have you tried to debug the code on a local computer? I had some troubles setting error messages on the server of my ISP. They managed them for all of the clients and hid them - thinking that it would prevent customers from seeing ugly warnings or errors (e.g. after php update or such).

  1. if you do not see any error try to test it on localhost
  2. if you do not see any connection timeout in you browser (at least my firefox prints it), then the timeout is not caused in between the server and client.

I suggest you try to debug the code - try to locate why the output stops exactly on line with the JS file inclusion. Does the script allways stop on the same line?

Bery
I installed everyting on my local machine now and there it generates just fine without the need of using echo ' '; Though the script runs much longer on my machine, since its not that powerful. So it definitly seams to be a server issue.
JochenJung
Try to check max_input_time in your php.ini or try to use ob_start() and ob_end_flush() methods. http://php.net/manual/en/function.ob-start.php. After that I am begging to be a little desperate :-/. It is really strange. Maybe just compare PHP versions between your localhost and server - the other time I had some serious problems with PHP 5.3 installed on production server and had to downgrade it again in order to run my apps properly again.
Bery
A: 

Make sure you're not sending out control characters. They'll terminate HTML output. You might want to try:

echo preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F]/','',$output);

This will output all characters including whitespaces (tabs, carriage returns, line feeds).

stillstanding
None of these caracters seams to be in my file (08:45:23) [home] od -t x1 stats_belegungsanfrage2.php | grep " 00"(08:45:33) [home] od -t x1 stats_belegungsanfrage2.php | grep " 08"(08:45:36) [home] od -t x1 stats_belegungsanfrage2.php | grep " 0b"(08:45:46) [home] od -t x1 stats_belegungsanfrage2.php | grep " 0c"(08:45:49) [home] od -t x1 stats_belegungsanfrage2.php | grep " 0e"(08:45:53) [home] od -t x1 stats_belegungsanfrage2.php | grep " 1f"(08:45:55) [home]
JochenJung
the regex above contains not just the characters u tried but a range of characters like from 0E thru 1F, so u may have missed something there
stillstanding
Oh, I missed that. Just checked for the other 15. Didn't find them as well in the file.
JochenJung
A: 

did you try to sens any header just at the begining of script (Content-Type or something like that)?

ts
Yes, header('Content-Type: text/html; charset=utf-8'); and session_start();I tried removing both, still the page stops loading after 10sec, if I don't echo ' ';
JochenJung
A: 

Here are my 2 cents:

First off i would make sure that all types of buffering is off. A gentleman was kinda enough to provide this code once:

@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
ob_implicit_flush(1);

After that i would suggest that you send an echo ' '; after some intervals. For instance if your code has a loop, send an echo after lets say every 10th iteration or something like that, based on how long each iteration takes. That way you aren't wasting time sending echos and you page stays alive as well.

Sabeen Malik
I'm starting to believe that there must be a proxy on my hosters side between my server and the internet. Readin all your comments its the only possibility I can think of. So doing echo ' '; before the 10sec timeout seams the best solution I have. There must not be a time where I don't sent data for more than 10sec.
JochenJung
A: 

How about sending the browser two components, one ajax block, and one iframe - hidden iframe may be.. Use the iframe's meta-refresh to keep it refreshing - and using the ajax block to wait till your php code outputs..

Well, this would be annother workaround. But my echo ' '; workaround is much easier. For me its more about understanding why this happens, than finding annother workaround.
JochenJung
A: 

It's possible your code is crashing Apache, or maybe PHP is crashing. In both cases no error messages could be sent back to the browser. Are you using the same versions of Apache and PHP on your home computer for testing? The same OS?

Instead of echo '' inside of your loop, trying sleep(10). You'll know it's not a timeout issue if the page doesn't go blank after 10 seconds.

Take a look at what you're doing inside the foreach loop. There's a hundred things that could crash Apache, PHP, or both. Especially in scenarios where you doing heavy data crunching.

mellowsoon
Just tried sleep(10). It still ends up loading after 10 sec. So it definitely a timeout issue.
JochenJung
That may not have worked, but I still think you might be crashing PHP or Apache. No error messages in the output, or in the log file means something bad happened before an error messages could be displayed/written. You can google "php crash apache blank page".
mellowsoon
Try creating a new script named test.php, and put nothing in it but <?php sleep(20); See if that "times out" after 10 seconds. You can also try a script like this http://pastebin.com/ZzW4bXVJ to ensure error logging is working.
mellowsoon