-1

So, i put together this code for a ftp server, i noticed that when i try to download large files (over 2gb) my ram would start to top out (i have 16gb ram) so i installed xsendfile, made it work, i got happy, my ram wouldn t go that high anymore, but then i looked at the download speed and i noticed that i would have around 3mb/s. Do you guys know how could i fix this problem? (i m using latest download of xamp for the server) [config.php is only for the credentials of mysql]

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Downloads</title>
<link rel="stylesheet" href="css/themes/lux.min.css" title="Grundlayout">
</head>
<body>
<div class="container">
<main>
<table class="table table-bordered">
<tr>
<th>ID</th>
<th>File name</th>
<th>File size</th>
</tr>
<?php



include "config.php";


if(isset($_GET['id'])){
    $id = $_GET['id'];
    $stat = $db->prepare("select * from newfiles where id=?");
    $stat->bindParam(1, $id);
    $stat->execute();
    $data = $stat->fetch();
    $file = $filepath.'/'.$data['filename'];
    
    if(file_exists($file)){
    ob_clean();  
    header("X-Sendfile: $file");
    header('Content-Type: '. $data['type']);
    header('Content-Transfer-Encoding: Binary');
    header('Content-Length: '.filesize($file));
    header('Content-disposition: attachment; filename="'.basename($file).'"');
    header('Content-Description: '.$data['description']);
    header('Content-Disposition: '. $data['disposition'].'; filename="'.basename($file).'"');
    header('Expires: '.$data['expires']);
    header('Cache-Control:'. $data['cache']);
    header('Pragma:'. $data['pragma']);
    readfile($file);
    
    flush();
    
    exit;
    }}
    

   
$stmt = $db->prepare("select * from $db_table");
$stmt->execute();
while($row = $stmt->fetch()){ ?>
<tr>
<td><?php print $row['id'] ?></td>
<td><?php print $row['filename'] ?></td>
<td><?php print filesize($filepath.'/'.$row['filename']).' Byte' ?></td>
<td class="text-center"><a href="./?id=<?php print $row['id'] ?>" class="btn btn-primary">Download</a></td>
</tr>
<?php
}
?>
</table>
</main>
<footer>File host provided by トリガー (Trigg3r)</footer>

</div>
</body>
</html>
  • Why is `readfile($file)` still in there? The point of `header("X-Sendfile: $file");` is that the web server will take care of reading the file content from disk and passing it on to the client. – CBroe Jan 11 '22 at 12:14
  • I used readfile($file) before i knew i needed xsendfile. Forgot to delete it – Th3 Outsider Jan 11 '22 at 21:06

1 Answers1

0

i solved this problem by modifying httpd.conf and writing this in there "EnableSendfile Off" and after that restarting the server