From 36e2ffa157430396d5d8a477bf2a5aa3facea6d4 Mon Sep 17 00:00:00 2001
From: =?utf8?q?S=2E=C3=87a=C4=9Flar=20Onur?= <caglar@cs.princeton.edu>
Date: Fri, 16 Apr 2010 19:46:24 +0000
Subject: [PATCH] Use readfile() function to reduce the memory footprint (and
 solve following);

PHP Fatal error:  Allowed memory size of 157286400 bytes exhausted (tried to allocate 92702721 bytes) in /var/www/html/planetlab/nodes/node_downloads.php on line 63
---
 planetlab/nodes/node_downloads.php | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/planetlab/nodes/node_downloads.php b/planetlab/nodes/node_downloads.php
index 2577c56..d43ada6 100644
--- a/planetlab/nodes/node_downloads.php
+++ b/planetlab/nodes/node_downloads.php
@@ -59,9 +59,11 @@ function deliver_and_unlink ($filename) {
   header ("Pragma: hack");
   header ("Cache-Control: public, must-revalidate");
 
-  // outputs the whole file contents
-  print (file_get_contents($filename));
-  
+  // turn off output buffering
+  ob_end_flush();
+  // outputs the whole file contents without copying it to memory
+  readfile($filename);
+ 
   // unlink the file
   if (! unlink ($filename) ) {
     // cannot unlink, but how can we notify this ?
-- 
2.47.0