rondog Posted September 2, 2010 Share Posted September 2, 2010 I have an FLV player and I am using a php file to read an FLV that is above webroot. It reads the FLV just fine, however, during its cache process or while it is still downloading, if I click on the home button (home button of the current site), the server does not respond until the FLV has been fully cached. Now this is only occuring in firefox, chrome and IE. In safari it works fine. Who know, maybe it is a header issue. Here is my script that I pass to my FLV player <?php include("connect.php"); if ($_SESSION['loggedIn'] == true) { $id = $_GET['id']; $query = mysql_query("SELECT video FROM reviews WHERE id = '$id'"); $row = mysql_fetch_array($query); $filename = "../../../armsmedia/videos/".$row['video']; header( 'Content-Description: File Transfer' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Disposition: attachment; filename='.basename( $filename ) ); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Pragma: public' ); header( 'Content-Length: ' . filesize( $filename ) ); ob_clean(); flush(); readfile( $filename ); exit; } ?> Quote Link to comment Share on other sites More sharing options...
rondog Posted September 2, 2010 Author Share Posted September 2, 2010 Could it possibly be the headers? I know browsers read headers differently which would be the reason it only works in Safari and no other browsers. Quote Link to comment Share on other sites More sharing options...
rondog Posted September 7, 2010 Author Share Posted September 7, 2010 I still haven't been able to figure this one out. I need some header experts =] Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 7, 2010 Share Posted September 7, 2010 Hi there rondog, I am not criticising you at all, just thought as I would point this out as it has caught me out a few times:- $querySql = "SELECT `video` FROM `reviews` WHERE `id` = $id";//If Id is an int it doesn't need quoting, only if it's a string $query = mysql_query($querySql) or die(mysql_error()); Build the sql string outside of the query, that way it's easier to debug if something goes wrong. Also for development work, pop the sql error handler on so that you get feedback from the mysql end too. Flv's usually require a timestamp on them I seem to recall, but it's been AGES since I have messed with that, so I don't want to commit to that, I just thought I should point out what I saw. Not sure on the exit; either, but I could be and probably am wrong, it's been a long day.. Cheers, Rw Quote Link to comment Share on other sites More sharing options...
rondog Posted September 7, 2010 Author Share Posted September 7, 2010 Ah I didn't know an int didnt have to be inside quotes. I'll know that from now on. Still though, my issue isnt getting the data. My query works fine and I can load the FLV into my player and it plays. The problem is if I click around the site while the video is still caching, the server does not respond until it is fully cached. This is doing it in IE, Firefox and Chrome. In Safari the site works just fine which brought me to thinking it was an issue with my headers. Quote Link to comment Share on other sites More sharing options...
rondog Posted September 7, 2010 Author Share Posted September 7, 2010 I tried the same thing with fopen and fread and same thing...ugh this is frustrating! Quote Link to comment Share on other sites More sharing options...
rondog Posted September 7, 2010 Author Share Posted September 7, 2010 ok making progress! I found that if I dont do a session_start() and dont test the $_SESSION['loggedIn'], it works! Whats up with that?? Quote Link to comment Share on other sites More sharing options...
rondog Posted September 7, 2010 Author Share Posted September 7, 2010 I figured it out..session_write_close() was the answer. <?php include("connect.php"); if ($_SESSION['loggedIn'] == true) { session_write_close(); $id = $_GET['id']; $query = mysql_query("SELECT video FROM reviews WHERE id = '$id'"); $row = mysql_fetch_array($query); $filename = "../../../armsmedia/videos/".$row['video']; header( 'Content-Description: File Transfer' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Disposition: attachment; filename='.basename( $filename ) ); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Pragma: public' ); header( 'Content-Length: ' . filesize( $filename ) ); ob_clean(); flush(); readfile( $filename ); exit; } ?> Quote Link to comment Share on other sites More sharing options...
rwwd Posted September 7, 2010 Share Posted September 7, 2010 rondog, Excellent news, that's one for the notes methinks - I haven't heard of this happening before, but then again, as I said, I don't use FLV much at all. Glad your sorted anyway. Cheers, Rw Quote Link to comment Share on other sites More sharing options...
rondog Posted September 7, 2010 Author Share Posted September 7, 2010 Yeah apparently starting a session put a lock on the file until the video was fully delivered. Finally I can continue on with other things I cant take all the credit though, I found the solution here: http://flowplayer.org/forum/2/30621 He used session_destroy() whereas that broke my site since I check the logged in session on every page request. Thats why I believe session_write_close() was the best solution Quote Link to comment 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.