[php] stream time out

Custom Title Activated
Loyal Member
Joined
Nov 28, 2004
Messages
2,236
Reaction score
0
I got one problem, and maybe you will help with the solution.

I made a small experiment, and saw that when user closes the browser, the script is still running for the defined amount of time.
PHP:
set_time_limit(10);

$cycle = true;

while ($cycle)
{
	$handle = fopen("01.txt", "a");
	
	if ($time < time() )
	{
		$time = time();
		
		fwrite($handle, $time . "\n" );
	**
	
	fclose($handle);
**

I am developing an audio relay script, which outputs mp3 stream.
It's quite simple. When user connects to specific php file via WinAmp, script connects to remote server and relays the data to the user. But I don't know when the user hangs down, so I have to set_time_limit(). But when specified time ends, the script stops his actions and user stops receiving audio stream. If I set set_time_limit(0), the stream will always be relayed, BUT when the user disconnects, the server will still try to fetch data from external server.

I want to kill the script as soon as the user disconnects from it.

The script works as an ordinary php file, not sock server in CLI, so I can't see if user opened/closed data relay socket.

Any suggestions?
 
Last edited:
i do not understand all those stream things, anyway you said it works as a usual php script, can't you simply add a code line to the script wich will mark somewhere db/textfile/cookie/whatever that user is connected and then make other script wich will simply check db/textfile/etc for marked n unmarked places, looped.

forgive me if i missunderstood your way of thinking.


-edit-

emm i just realized this post is 2 weeks old, but anyway if you haven't found solution yet this is my suggestion.
 
erm.. NO!
I got an audio stream taken from elsewhere and I want to know if the client disconnected from the script so it could stop ripping the audio from elsewhere..
 
Back