Web server not working

I’m trying to build a small computer for managing aquarium with Arduino Uno Rev.3, ethernet shield, integrating a web server for viewing of the sensors, and the interaction with the outputs;
In the cycle of the loop if you call the function Osmorgolatore (), the web server It returns a blank page, if I comment the function ok.
What can it be?
Another thing how can I save memory space and size of the sketch?
I am attaching sketch complete, if you want I can send you the htm page
Thanks in advance

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

// size of buffer used to capture HTTP requests
#define REQ_BUF_SZ   50

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x8B, 0xB1 };
IPAddress ip(192, 168, 1, 177); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80
File webFile;               // the web page file on the SD card
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer
double Temp_inH2O;
boolean LED_state[4] = {0}; // stores the states of the LEDs
String POMPARAB_state[4] = {" "};
double waterlevel;
boolean errore_pompa =0;
int iniziotimeout=0;
unsigned long chktrab = 0;
unsigned long chkwaves = 0;  


void setup()
{
  
    // disable Ethernet chip
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);

    Serial.begin(9600);       // for debugging
    
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
}

void loop()
{
    
  
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // buffer first part of HTTP request in HTTP_req array (string)
                // leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
                if (req_index < (REQ_BUF_SZ - 1)) {
                    HTTP_req[req_index] = c;          // save HTTP request character
                    req_index++;
                }
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    // remainder of header follows below, depending on if
                    // web page or XML page is requested
                    // Ajax request - send XML file
                    if (StrContains(HTTP_req, "ajax_inputs")) {
                        // send rest of HTTP header
                        client.println("Content-Type: text/xml");
                        client.println("Connection: keep-alive");
                        client.println();
                         SetLEDs();
                         SetRAB();
                        // send XML file containing input states
                        XML_response(client);
                    }
                    else {  // web page request
                        // send rest of HTTP header
                        client.println("Content-Type: text/html");
                        client.println("Connection: keep-alive");
                        client.println();
                        // send web page
                        webFile = SD.open("index.htm");        // open web page file
                        if (webFile) {
                            while(webFile.available()) {
                                client.write(webFile.read()); // send web page to client
                            }
                            webFile.close();
                        }
                    }
                    // display received HTTP request on serial port
                    Serial.print(HTTP_req);
                    // reset buffer index and all buffer elements to 0
                    req_index = 0;
                    StrClear(HTTP_req, REQ_BUF_SZ);
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1000);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
     Temp_inH2O = ReadTemperatureLM35(3,10);
     Osmoregolatore();// If I do not comment, the web server It returns a blank page
}

double CheckLevel(int Channel)
 {
 
  double livello;
 
    livello = analogRead(Channel); 
   

  return livello;
}
void Osmoregolatore ()
 { unsigned long timeoutrab = 5000;
   unsigned long antiwaves =10000;
      waterlevel = CheckLevel(5);
  if((waterlevel<300.00) && (errore_pompa==0)) {
        if(iniziotimeout==0){
           chkwaves=millis();
           iniziotimeout=1;
          }
      //Controllo che non sia un ondeggiamento del livello
    
    }
     if(chkwaves+antiwaves<millis())
     {//dopo circa 10 secondi attivo il rabboco
        if(iniziotimeout==1){
           POMPARAB_state[0]="On";
           iniziotimeout=2;
           chktrab=millis();
           digitalWrite(8,HIGH);
           Serial.print("Livello basso");
          Serial.println(waterlevel);
          
            }
       
      }
      
     if((chktrab+timeoutrab<millis()) && (errore_pompa==0) && (iniziotimeout==2)){
         errore_pompa=1;
         digitalWrite(8,LOW);
         Serial.print("Timeout pompa");
         Serial.println(waterlevel);
         errore_pompa=1;
         POMPARAB_state[0]="On";
    }
    
 if((waterlevel>300.00) && (iniziotimeout==2)){
    POMPARAB_state[0]="Off";
    digitalWrite(8,LOW);
    Serial.print("Livello Ripristinato");
    Serial.print(" ");
    Serial.println(waterlevel);
    if(errore_pompa==1){
      POMPARAB_state[0]="Errore";
    Serial.println();
    Serial.print("Errore sensore"); }
    chkwaves=0;
    chktrab=0;
    iniziotimeout=0;
    }
   }

What can it be?

99.9% chance that you are out of memory.

String POMPARAB_state[4] = {" "};

Get rid of every String (especially arrays of Strings).

Keep literals out of SRAM:
Serial.println(F(“Initializing SD card…”));

Server code showing how the F() macro can be used on static text lines to save memory.

// zoomkat's meta refresh data frame test page 8/17/13
// use http://192.168.1.102:84 in your brouser for main page
// http://192.168.1.102:84/data static data page
// http://192.168.1.102:84/datastart meta refresh data page
// for use with W5100 based ethernet shields
// set the refresh rate to 0 for fastest update
// use STOP for single data updates

#include <SPI.h>
#include <Ethernet.h>

const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // arduino ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
unsigned long int x=0; //set refresh counter to 0
String readString; 

//////////////////////

void setup(){
  Serial.begin(9600);
    // disable SD SPI if memory card in the uSD slot
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  server.begin();
  Serial.println(F("meta refresh data frame test 8/17/13")); // so I can keep track of what is loaded
}

void loop(){
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (readString.length() < 100) {
          readString += c; 
         } 
        //check if HTTP request has ended
        if (c == '\n') {

          //check get atring received
          Serial.println(readString);

          //output HTML data header
          //client.println("HTTP/1.0 200 OK");
          //client.println("Content-Type: text/html");
          //client.println();
          
          client.print(F("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));

          //generate data page
          if(readString.indexOf("data") >0) {  //checks for "data" page
            x=x+1; //page upload counter
            client.print(F("<HTML><HEAD>"));
            //meta-refresh page every 1 seconds if "datastart" page
            if(readString.indexOf("datastart") >0) client.print(F("<meta http-equiv='refresh' content='1'>")); 
            //meta-refresh 0 for fast data
            if(readString.indexOf("datafast") >0) client.print(F("<meta http-equiv='refresh' content='0'>")); 
            client.print(F("<title>Zoomkat's meta-refresh test</title></head><BODY>
"));
            client.print(F("page refresh number: "));
            client.print(x); //current refresh count
            client.print(F("

"));
            
              //output the value of each analog input pin
            client.print(F("analog input0 is: "));
            client.print(analogRead(analogInPin0));
            
            client.print(F("
analog input1 is: "));
            client.print(analogRead(analogInPin1));
                        
            client.print(F("
analog input2 is: "));
            client.print(analogRead(analogInPin2));
            
            client.print(F("
analog input3 is: "));
            client.print(analogRead(analogInPin3));
                                    
            client.print(F("
analog input4 is: "));
            client.print(analogRead(analogInPin4));
            
            client.print(F("
analog input5 is: "));
            client.print(analogRead(analogInPin5));
            client.print(F("
</BODY></HTML>"));
           }
          //generate main page with iframe
          else
          {
            client.print(F("<HTML><HEAD><TITLE>Zoomkat's frame refresh test</TITLE></HEAD>"
            "Zoomkat's Arduino frame meta refresh test 8/17/13"
            "

Arduino analog input data frame:
"
            "&nbsp;&nbsp;<a href='/datastart' target='DataBox' title=''yy''>META-REFRESH</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/data' target='DataBox' title=''xx''>SINGLE-STOP</a>"
            "&nbsp;&nbsp;&nbsp;&nbsp;<a href='/datafast' target='DataBox' title=''zz''>FAST-DATA</a>
"
            "<iframe src='/data' width='350' height='250' name='DataBox'>"
            "</iframe>
</HTML>"));
          }
          delay(1);
          //stopping client
          client.stop();
          //clearing string for next read
          readString="";
        }
      }
    }
  }
}

Thanks, I William try this. Stay tuned :)

Thanks, I used F() macro and all works! Another question it's possible to use web server and bleadfruit library togheter to use Iphone interface but even web interface? With Arduino uno I think it's really hard cause it's low memory, it's right?

gozilla: Thanks, I used F() macro and all works! Another question it's possible to use web server and bleadfruit library togheter to use Iphone interface but even web interface? With Arduino uno I think it's really hard cause it's low memory, it's right?

You will need to explain what you are talking about in more detail, especially as to what bleadfruit library is.

The BLE Adafruit is this http://www.adafruit.com/products/1697

I need to know if it's possible to use this and also the ethernet shield on an Arduino uno, because if I include the ethernet library and the BLE Adafruit Library, the space remaining for code is very very small. Solution possible? I need to control arduino from internet and even from Iphone 4s/5/5s or any using Bluetooth low energy. Thanks

I need to know if it's possible to use this and also the ethernet shield on an Arduino uno, because if I include the ethernet library and the BLE Adafruit Library, the space remaining for code is very very small. Solution possible?

Use a Mega.