[PHP] spawning a process that uses pipes - doesn't terminate when webpage download is canceled
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? -FM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Fw: [PHP] mysql_query takes long time...
- Original Message - From: "flint" To: "דניאל דנון" Sent: Sunday, May 31, 2009 9:21 AM Subject: Re: [PHP] mysql_query takes long time... have you actually tried running the script against your data? i'm running MySQL/PHP on an old P3/933Mhz box with only 384M memory... I had a situation just like yours. I had a text file of 600,000 lines, the script reads a line, does regex matches/replacements on it, and inserts to SQL. it took the script about 15 mins to process the entire file and put all the data into MySQL. and remember that's on a P3/933 so a faster system will obviously speed that up significantly don't worry about the time MySQL reports for an individual query. it is dependent on many factors. but once you open your SQL connection and start streaming data in it will actually go much faster than that. just run the script and give it a try... even add some debugging output, somethign like this maybe: $counter = 0; while (!feof($fhandle)) { $line = fgets($fhandle); process_line($line); insert_into_sql($line); $counter++; if ($counter % 100 = 0) { echo $counter . " records done\n"; } } that will give you a printout every 100 records processed... a nice way to track progress. FM - Original Message - From: "דניאל דנון" To: "PHP General List" Sent: Sunday, May 31, 2009 7:18 AM Subject: [PHP] mysql_query takes long time... I've a file of about 500,000 lines, each line contains a string in variety of lengths, but no less then 3 characters and usually no more then 120. average of about 80, and maximum of about 250. I made a PHP script to fetch the data (using fgets), process it and insert it to a MySQL database. The problem is inserting to MySQL takes about 0.02 seconds, which looks like nothing - but when you have 500,000 lines to insert... The while goes like that: fgets from file x1 = some function about the string x2 = some other function about the string x3 = the string insert into table (field1, field2, field3) VALUES (x1, x2, x3) (pseudo-code) I was wondering, is there any faster way to perform it, assuming I have to do it with PHP? also, if it matters - the MySQL table got id in auto increment. Yours, Daniel. -- Use ROT26 for best security -- 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
- 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
[PHP] spawning a process that uses pipes - doesn't terminate when webpage download is canceled
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? -FM -- 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'tterminatewhen webpage download is canceled
Rob: Perfect explanation of my problem. do you have any sample code I could look at for proc_open? It looks like it might do what I need but it's a lot more complex than popen. fm -- From: "Robert Cummings" Sent: Monday, June 01, 2009 10:01 AM To: "bruce" Cc: "'PHP-General List'" Subject: RE: [PHP] spawning a process that uses pipes -doesn'tterminatewhen webpage download is canceled On Mon, 2009-06-01 at 07:52 -0700, bruce wrote: hi robert... i got the popen/php process but i don't see how one can stop a browser/apache process, and somehow reattach to the browser process.. unless he's talking about stopping a process within the app's context.. and then contniuing.. Hi Bruce, He's spawning child processes to handle the audio changes. These processes are separate processes from the PHP script being run by the webserver. However, they are children of the PHP script process since they have been started by the PHP script via popen() or proc_open(). His problem is that when the user changes page mid load, or shuts down the browser, the PHP script (the parent) is killed off by the webserver, but the child processes, sox and lame, continue to run. This ends up polluting CPU/memory with useless processes. What he wants is to have these processes also die. So by using proc_open() he can retrieve the output from the processes he has started and send that to the connected browser in chunks, but also detect if the browser has dropped its connection in which case he can manually kill of the child processes that aren't being killed automatically. HTH. 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
[PHP] check a variable after EACH function
This might seem silly but here's what I'm trying to do Suppose I have some kind of check variable - say for example $abort_now. Or it could be a function. Something to be evaluated to a value. I want to execute a block of statements, but after EACH statement executes, check the value of $abort_now and if it is true, break; out of the block. Here's an example do { do_something(); do_something_else(); do_another_thing(); do_yet_another_thing(); and_keep_doing_things(); } while ($abort_now != 1); What I want to happen is for each statement to execute, and keep looping around, until the $abort_now variable is set to 1. Now, suppose any one of the statements in that block may cause $abort_now to become 1. If that happens, I want the block to stop executing immediately and not continue executing further statements. For example, do_another_thing() causes $abort_now to equal 1. I do not want do_yet_another_thing or keep doing things to execute. I want the loop to stop right there. The only way I can think of doing it is to insert a check after each statement: do { do_something(); if ($abort_now == 1) { break; } do_something_else(); if ($abort_now == 1) { break; } do_another_thing(); if ($abort_now == 1) { break; } do_yet_another_thing(); if ($abort_now == 1) { break; } and_keep_doing_things(); if ($abort_now == 1) { break; } } while (TRUE); This might work for 2 or 3 statements but imagine a block of say 15 statements. Having a check after each one would look ugly, and cause trouble if the condition needed to be changed or if I instead decided to check it, say, against a function. So is this possible to do with built in code? or am I stuck with having to put a check after each statement in? thanks fm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] RE: [PHP-WIN] MSSQL Functions
Toby, Yes, the client is requires because the MSSQL module uses some libraries from the client to function. I don't know which one. If Frank see this, he might be able to give you some detailed insight. I just know it has to be installed. -Flint -Original Message- From: Toby Miller [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 07, 2001 4:04 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: [PHP-WIN] MSSQL Functions Hey all, I've got a question about using the MSSQL Functions. The only way I've been able to use them is to install Microsoft SQL Client on the web server. Is there any way to get around this to use the MSSQL Functions without installing a copy of Microsoft SQL Client? Right now I am using the ODBC Functions to get around the problem, but I was wondering if it just relies on some DLL's that I could copy to the server or something like that? I know that people are using the MSSQL Functions on Linux and they obviously didn't need to install Microsoft SQL Client to get them to work so I'm just hoping there's a way around it? Thanks, Toby -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]