detecting a file in use

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
What should be used to know when a request has been made for the server to
load an audio file?
As I see it, the server has to know that a request has been made.

You, the user, using your browser, sees a list of songs that you can play.
You click that link, the browser sends a request to fetch that file.
This is the point in time when I want to know that the request has been
Javascript takes care of the playing side.
But still, the server has to have some way of knowing which audio file is
being requested and whether or not buffering is needed.

Now that the audio file has played, the server needs to know that file has
completed downloading.
So what do I use to know this has happened?

Re: detecting a file in use

On 06/11/13 18:12, richard wrote:
Quoted text here. Click to load it

three ways to do it

Simple: parse the log file
Medium: use a wrapper file which notify that someone requested a file  
and then serve the file, this can destroy fast  
forward/rewind/pause/resume features.
Complicated: Make the JavaScript to call a page and tell which file the  
user is loading and if they do buffer or not.

Quoted text here. Click to load it

If you use wrapper and the page terminates, then it's finished with the  
download. If you use the javascript then make an ajax call and tell that  
the song has finished to play.



Re: detecting a file in use

On 11/06/2013 09:12 AM, richard wrote:
Quoted text here. Click to load it

What you probably want is to use a PHP script that is masquerading as
the audio file.  You can make a directory called 'my_song.wav', and have
an index.php inside that directory.  At least with Apache, it will detect
the directory and instead load the index.php file.  Your PHP code in that file can
introspect it's request with $PHP_SELF and find out what song was asked
for.  Then, you can fopen() the real audio file (could be a sibling of
index.php, or in some other audio directory), and print it out to the
browser.  Now your are in PHP, and you know that the request for the
song has been made.  You won't be able to tell when the song
has finished, because there will be output buffering going on.

You may be able to do ob_start() before you print the .wav content,
then when you do ob_end_clean(), I would guess that when that statement
has finished you at least know that the server is done sending the
audio content.  That still doesn't guarantee that the user has heard the
end of the song on their end however.


Re: detecting a file in use

On 06/11/13 17:12, richard wrote:
Quoted text here. Click to load it
YOU don't.
The operating system knows, because the IP connection has (probably)  
gone. The file may or may not remain in cache depending on how much RAM  
the server has, and how busy it is.


(in-ep-toc’-ra-cy) – a system of government where the least capable to  
lead are elected by the least capable of producing, and where the  
members of society least likely to sustain themselves or succeed, are  
rewarded with goods and services paid for by the confiscated wealth of a  
diminishing number of producers.

Re: detecting a file in use

On 06-11-2013 18:12, richard wrote:
Quoted text here. Click to load it

You need to have a basic understanding of the HTTP-protocol.
This is (i think it is) considered off-topic in comp.lang.php

Maybe microsoft.public.winhttp is a good place to ask?

Site Timeline