Skip to content

Commit

Permalink
Use readfile() for serving protected uploads
Browse files Browse the repository at this point in the history
I suspect that one performance problem we have stems from loading
binary files into memory, and then using `echo()` to send them to
the client.

This switches off output buffering and uses `readfile()`.
  • Loading branch information
leedxw committed May 22, 2024
1 parent 3ffecbb commit 6722aaa
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ function dxw_members_only_serve_uploads()
$type = $mime['type'];
}

header('Content-type: ' . $type);
echo file_get_contents($file);
die();
header('Content-Type: ' . $type);
header('Content-Length: ' . filesize($file));
header('Last-Modified: ' . gmdate('D, d M Y H:i:s T', filemtime($file)) );
ob_get_flush();
readfile($file);
exit;
}
}
}
Expand Down

0 comments on commit 6722aaa

Please sign in to comment.