Ethernet shield stop responding after some hours

My Ethernet shield stop responding after some hours and needs restart with the restart button
is this hardware related?

Second question is PWM pin (4) occupied by the SD card , i dont use SD card , but i need the Pin 4 for some other purposes.

void StartWeb()
  
{
 
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
       if (client.available()) {
       
         char c = client.read();
        
          // serch parameter from "HTTP GET"
          if(gflag){
            if(c != ' '){
                parm += c;
            }else{
                gflag = false;
            }
          }
          if(c == '?' && parm == ""){
            gflag = true;
 
   if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header

         if(parm == ""){ // normal HTTP access
                client.println(F("HTTP/1.1 200 OK"));
                client.println(F("Content-Type: text/html"));
                client.println(F(""));
	 	client.println(F("<html><head></head><body>HELLO!</body></html> "));
                break;
                
               }
               
              else{ // using XMLhttpObject access  
                      //IF SUBMIT FROM TIME
 
                        client.println(F("HTTP/1.1 200 OK"));
                        client.println(F("Content-Type: text/html"));client.println(F(""));
                       int check = parm.indexOf('=');
                          if(check != -1){
				//TIME
				if (hrs < 10) client.print(F("0"));client.print( hrs );client.print(":");if (mins < 10) client.print(F("0"));client.print(mins);client.print(F(":"));if (secs < 10) client.print(F("0"));				
				client.print(secs);client.print(F(" "));if (date < 10) client.print(F("0"));client.print(date);client.print(F("-"));if (month < 10) client.print("0");client.print(month);client.print(F("-"));if (year < 10)client.print(F("0"));client.println(year);
				 
                      } 
                     
                   }
                     
 
            parm = "";
          }
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
 
    // close the connection:
    client.stop();
  }///////
}

what i mean stop responding , is that , i cant even ping to it , the mega is running fine, it connected in a hub , and the hub to my rooter

Have you tried any other server code as a test? Here is mine in the playground.
http://playground.arduino.cc/Code/WebServerST

edit: If the ethernet port LEDs are still on, then this is an indication there are no available sockets:

i cant even ping to it

Second question is PWM pin (4) occupied by the SD card , i dont use SD card , but i need the Pin 4 for some other purposes.

If you don't insert a card into the slot you can use pin 4 for any purpose you like.

SurferTim:
Have you tried any other server code as a test? Here is mine in the playground.
Arduino Playground - HomePage

edit: If the ethernet port LEDs are still on, then this is an indication there are no available sockets:

i cant even ping to it

all the Ethernet leds
COLL
FULLD
100M
LINK
PWR

are ON only the TX and RX are not.. Probably there are no available sockets., but how do i handle this , is there any example?

is there any example?

Yes. Did you try my code in the link I posted above? It should close the sockets correctly.

i added this part

loopCount++;

      // if 10000ms has passed since last packet
      if(loopCount > 10000) {
        // close connection
        client.stop();
        Serial.println("\r\nTimeout");
      }

and so far after 2 days , and "abuse" stress test , the controller respond without problems..! thanks!

Thanks for that info. That timeout code is the latest change I made just a few days ago.