d22552000 Posted December 28, 2007 Share Posted December 28, 2007 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' ? Quote Link to comment https://forums.phpfreaks.com/topic/83516-solved-download-script-freezing-execution/ Share on other sites More sharing options...
d22552000 Posted December 28, 2007 Author Share Posted December 28, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/83516-solved-download-script-freezing-execution/#findComment-424932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.