Autor Zpráva
Tomkinss
Profil
Potreboval by som poradiť s jedným php kódom, ktorý generuje obsah na stiahnutie.
Všetko funguje ako má, až nato, že 1 užívateľ spotrebuje asi 200 MB RAM servera. Neviem či to spôsobuje overovanie pripojenia, alebo rozdelovanie súboru cez while. Môžete sa nato niekto pozrieť a poradiť mi pravdepodobnú príčinu tak vysokej záťaže ?

   $size = $size * 1024;
  /* Create the output file */
  
  header("Content-type: ".$ext." File");
  header("Content-Transfer-Encoding: Binary");
  header("Content-length: ".$size);
  header("Content-disposition: attachment; filename=\"".$name."\"");
  
    // Set max speed for free user
    $kb_s=(int)(1000000/$speed);
    
    //Set PHP not to cancel execution if the connection is aborted
    //and drop the time limit to allow for big file downloads
    ignore_user_abort(true);
    set_time_limit(0);
    
    $fp=fopen($file, 'r');
    $update_status = 1;
    while(!feof($fp)) {
      echo fread($fp, 1024);
      
      //Make sure the data gets flushed properly or the connection check won't work
      flush();
      ob_flush();
   
      //Check then connection status and exit loop if aborted
      if(connection_status() != CONNECTION_NORMAL || connection_aborted()) {
        $update_status = 2;
        break;
      }
   
      if ($speed != 0) {
        usleep($kb_s);
      }
    } // end while..
    fclose($fp);

    // Update finish download
    mysql_query("
      UPDATE
        `downloads`
      SET
        `download_status` = '" . $update_status . "'
      WHERE
        `id` = '" . $last_down . "'
    ");

  //Never hurts to ensure that the script halts execution
  die();
 

Za každu radu vopred ďakujem.
Davex
Profil
Uvedený kód by tolik paměti používat neměl a při testu mi spotřeboval kolem 600 KB paměti.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0