Re: [PHP] spawning a process that uses pipes - doesn't terminatewhen webpage download is canceled

2009-06-01 Thread Robert Cummings
On Mon, 2009-06-01 at 05:15 -0500, flint wrote:
> - Original Message - 
> From: "Robert Cummings" 
> To: "flint" 
> Cc: "PHP-General List" 
> Sent: Sunday, May 31, 2009 10:15 PM
> Subject: Re: [PHP] spawning a process that uses pipes - doesn't 
> terminatewhen webpage download is canceled
> 
> I'm already doing something like that... here's what I have basically
> 
> $o = popen($cmd);
> while (!feof($o)) {
>   $buffer = fread($o,4096);
>   echo $p;
> }
> exit();
> 
> Ok so I can add in the statements to stop auto aborting, use connection 
> aborted... but how do i kill the process chain itself? If I simply pclose 
> the process it has the same effect - the other spawned processes keep 
> running. I figured out what's happening is the lame process keeps going 
> utnil it finishes, and apparently is sending its data to the proverbial bit 
> bucket... and in a process tree it moves from being under the http process 
> to being under init itself...

You can use the linux shell command ps:

exec( 'ps --ppid '.getmypid(), $children );

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] spawning a process that uses pipes - doesn't terminatewhen webpage download is canceled

2009-06-01 Thread Robert Cummings
On Sun, 2009-05-31 at 21:23 -0700, bruce wrote:
> hi robert.,,
> 
> now you've got me curious..
> 
> you state...
> 
> -Use something else to pass the data back to the user... popen() comes to
> -mind or proc_open(). Then disable auto abort on user disconnect via
> -ignore_user_abort(). Then after sending periodic data chunks, check the
> -user connection status via connection_aborted(). If your script finds
> -that the user has aborted, then kill all the processes in the pipeline
> -from the PHP script before finally aborting the PHP script itself.
> 
> but if the user is using a browser session... which has a web server
> connection... are you siggesting that the server app spawns off a child
> process via the popen, and that the child somehow connects to the existing
> browser session??
> 
> walk through the psuedo logic/flow of this if you don't mind.. i must be
> missing something..

The PHP session controls the popen() or proc_open() session. The PHP
session can detect that the user has aborted and then shutdown the
popen() or proc_open() processes.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] spawning a process that uses pipes - doesn't terminatewhen webpage download is canceled

2009-06-01 Thread flint


- Original Message - 
From: "Robert Cummings" 

To: "flint" 
Cc: "PHP-General List" 
Sent: Sunday, May 31, 2009 10:15 PM
Subject: Re: [PHP] spawning a process that uses pipes - doesn't 
terminatewhen webpage download is canceled


I'm already doing something like that... here's what I have basically

$o = popen($cmd);
while (!feof($o)) {
 $buffer = fread($o,4096);
 echo $p;
}
exit();

Ok so I can add in the statements to stop auto aborting, use connection 
aborted... but how do i kill the process chain itself? If I simply pclose 
the process it has the same effect - the other spawned processes keep 
running. I figured out what's happening is the lame process keeps going 
utnil it finishes, and apparently is sending its data to the proverbial bit 
bucket... and in a process tree it moves from being under the http process 
to being under init itself...


fm


Use something else to pass the data back to the user... popen() comes to
mind or proc_open(). Then disable auto abort on user disconnect via
ignore_user_abort(). Then after sending periodic data chunks, check the
user connection status via connection_aborted(). If your script finds
that the user has aborted, then kill all the processes in the pipeline
from the PHP script before finally aborting the PHP script itself.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] spawning a process that uses pipes - doesn't terminatewhen webpage download is canceled

2009-05-31 Thread bruce
hi robert.,,

now you've got me curious..

you state...

-Use something else to pass the data back to the user... popen() comes to
-mind or proc_open(). Then disable auto abort on user disconnect via
-ignore_user_abort(). Then after sending periodic data chunks, check the
-user connection status via connection_aborted(). If your script finds
-that the user has aborted, then kill all the processes in the pipeline
-from the PHP script before finally aborting the PHP script itself.

but if the user is using a browser session... which has a web server
connection... are you siggesting that the server app spawns off a child
process via the popen, and that the child somehow connects to the existing
browser session??

walk through the psuedo logic/flow of this if you don't mind.. i must be
missing something..

thanks


-Original Message-
From: Robert Cummings [mailto:rob...@interjinn.com]
Sent: Sunday, May 31, 2009 8:16 PM
To: flint
Cc: PHP-General List
Subject: Re: [PHP] spawning a process that uses pipes - doesn't
terminatewhen webpage download is canceled


On Sun, 2009-05-31 at 08:52 -0500, flint wrote:
> sent this before, don't know if it went through... someone please reply if
> it went, even if they don't know answer?...
>
> so here's the scenario..
>
> I have a site that uses php with a database to offer sound files to
> users using streaming methods.
>
> the request page has options, allowing the user to modify the sound
> file in various ways, before having it sent to them
>
> Here's the problem:
>
> The method i'm using to feed the data to the user is to run the source
> file through various piped commands, with the resulting audio being
> dumped to stdout, and then using passthru in php to get that data to
> the enduser.
>
> here's an example, for serving an MP3 with its pitch/speed changed by sox:
>
> passthru("lame --quiet --decode \"" . $in_file . "\" - | " .
>  "sox -V -S -t wav - -t wav - speed " . $speed_factor . " | "
.
>  "lame --quiet " . $lame_params . " - -");
>
> This works just fine, except the problem is if the end user aborts the
> transfer (e.g. stops playback in the media player, cancels download of
> the mp3, whatever) then it leaves behind both the sox process and the
> decoder LAMe process along with the sh that's running them. the only
> process that exits is the final encoding lame process. If the sound
> file runs to completion, everythign exits properly.
>
> But this obviously means enough "cancelling" of downloads means the
> server ends up with a huge batch of stuck processes! And I even tried
> simply killing the 'host' sh process, and the lame and sox processes
> remain anyway. The only way I've been able to deal with this is
> manually killing the lame and sox processes directly.
>
> is there any way I can make this work, such so that if the user
> cancels the transfer, all relavent processes are killed rather than
> just the single process that's feeding output into php?

Use something else to pass the data back to the user... popen() comes to
mind or proc_open(). Then disable auto abort on user disconnect via
ignore_user_abort(). Then after sending periodic data chunks, check the
user connection status via connection_aborted(). If your script finds
that the user has aborted, then kill all the processes in the pipeline
from the PHP script before finally aborting the PHP script itself.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php