Jump to content

[SOLVED] Download Script Freezing Execution


d22552000

Recommended Posts

When this script is running, and someone is download a file, ALL other php-cgi.exe requests wait for this script to end, before executing. How can I fix this?

 

Direct Download Script:

<?PHP

function getfile($TYPE,$B,$PATH) {
mysql_query('UPDATE `filepirate`.`FILES` SET `Downloads`=`Downloads`+1
WHERE `ID`='.$_GET['id']) or die(mysql_error());

header('Content-Disposition: attachment; filename="'.$B.'"');
header('Content-Description: File Transfer');
header('Content-Length: '.filesize($PATH));
header('Content-type: '.$TYPE);
header('Connection: close');

readfile($PATH); exit();
}

function eror($RET) {
echo $RET;
die();
}

$NAME = $_GET['id'];

/* MYSQL CONNECTION */
mysql_connect('localhost','root','');
$r = mysql_query("SELECT * FROM `filepirate`.`FILES` WHERE ID=$NAME;") or eror(mysql_error());

while(list($ID,$B,$PASS,$DESC,$TYPE,$DOWN)= mysql_fetch_row($r)) {
$PATH = './Files/'.$ID;

if (file_exists($PATH) && !empty($_GET['id'])) {
if (!empty($PASS)) {
if (!empty($_POST['pass'])) {
if ($PASS==$_POST['pass']) {
getfile($TYPE,$B,$PATH);
} else { eror('Invalid Pass.  Pass Not Right'); }
} else { eror('No Password Entered'); }
} else { getfile($TYPE,$B,$PATH); }
} else { eror('Invalid File.  File Not Here!'); }
}
?>

(I had to get rid of my indentation because of this forum f***ing

up the spaces, replacing them with  

 

Why when this is running, does the entire website 'wait' ?

Link to comment
Share on other sites

ok this is solved, I figured it out.

 

Turned out that when php include()s a file, it locks it from reading by any other process id.  EVEN if you do include_once() it still locks said file from writing.  THis was freezing hte script because every other page on the server happened to use the same inc/conf.php file in it's header.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.