Jump to content

readfile() causing browser to hang..I think..


rondog

Recommended Posts

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;
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
}
?>

Link to comment
Share on other sites

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  8)

 

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

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.