note 115548 deleted from function.symlink by salathe
| From: | salathe@php.net | Date: | Fri, 22 Aug 2014 08:09:47 +0000 |
| Subject: | note 115548 deleted from function.symlink by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-200260@lists.php.net to get a copy of this message | ||
Note Submitter: koval at apisys.pl
----
In addition to note posted by olszewski_marek at yahoo dot com:
You could delete the symlink after few seconds - even if file is quite large, OS should store it in
memory for http server to properly serve it. Here's how:
<?php
// Make sure script keeps executing even if user aborts
ignore_user_abort(true);
// Create symlink
mkdir($downloaddir . $string, 0777);
symlink($safedir . $filename, $downloaddir . $string . "/" . $filename);
// Redirect client
Header("Location: " . $downloadURL . $string . "/" . $filename);
// Make sure client gets redirect headers, any output from now on should be ignored by client
flush();
ob_flush();
// A bit of timeout
sleep(3);
// Remove symlink
unlink($downloaddir . $string . "/" . $filename);
?>
With this approach You're sure that You have no unnecessary symlinks, AND no symlinks are
deleted with high concurency.
I've tested this on some highly limited hosting service - it saves huge ammounts of resources
(symlink itself, but also directory scans). above 10000 downloads in 24 hours - no complaints, no
errors reported.