note 115548 added to function.symlink
| From: | kovalatapisys.pl | Date: | Wed, 13 Aug 2014 16:03:37 +0000 |
| Subject: | note 115548 added to function.symlink | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200184@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 46.17.113.50
Probable Submitter: 46.76.129.167
----
Manual Page -- http://php.net/manual/en/function.symlink.php
Edit -- https://master.php.net/note/edit/115548
Del: integrated -- https://master.php.net/note/delete/115548/integrated
Del: useless -- https://master.php.net/note/delete/115548/useless
Del: bad code -- https://master.php.net/note/delete/115548/bad+code
Del: spam -- https://master.php.net/note/delete/115548/spam
Del: non-english -- https://master.php.net/note/delete/115548/non-english
Del: in docs -- https://master.php.net/note/delete/115548/in+docs
Del: other reasons-- https://master.php.net/note/delete/115548
Reject -- https://master.php.net/note/reject/115548
Search -- https://master.php.net/manage/user-notes.php