Re: mod_perl 2 and IPC::Open3
On Thu 04 Sep 2008, Tina Müller wrote: > $pid = open3($wtr, $rdr, $err, > '/usr/bin/source-highlight', '-s', 'perl', '-css', > '--no-doc'); > print $wtr $content; > close $wtr; > warn __PACKAGE__.':'.__LINE__.": before read loop\n"; > while (<$rdr>) { > # this is not executed > warn __PACKAGE__.':'.__LINE__.": line $_\n"; > $highlighted .= $_; > } Don't know if it relates to the problem but this code is quite fragile. It depends upon whether $content completely fits into the operating systems pipe buffer. In your program the print $wtr or the close $wtr statements may infinitely block if $content is too large. To illustrate that try this: perl -e 'pipe my ($r, $w) or die "pipe: $!\n"; print $w "x"x64000; warn "printed\n"; close $w;' Here a pipe is created and written to but never read from. This example succeeds on my linux box. If 64000 is raised to 69000 the "print $w" succeeds and I see the output of warn(). But the process never ends. It is blocked in the close() operation. If the buffer length is raised a bit further to 7 I don't even see the warning. The process is blocked in the print() operation. The pipe buffer size depends upon the operating system. So your numbers may vary. I'd recommend to rewrite that piece based on either perl's select(), IO::Select or some kind of event library like Lib::Event, EV, Event or even POE. In all cases you have to use non-blocking IO for reading and writing combined with sysread/syswrite. Further, I'd suggest a bit of error handling. All those operations open3, print, close may fail. Only open3 reports the failure via an exception. Also, you may want to watch out for SIGPIPE. Torsten -- Need professional mod_perl support? Just hire me: [EMAIL PROTECTED]
question on downloading CGI
Hello, I want to generate a data file which should be downloaded by clients. Rather than generate this file and put it in a web dir and tell clients to download it, is there any way to generate the content dynamicly and put it to cients? I mean I don't want to generate the temporary file. Thanks. Jen.
Re: question on downloading CGI
On Fri, Sep 5, 2008 at 12:09 PM, <[EMAIL PROTECTED]> wrote: > Hello, > > I want to generate a data file which should be downloaded by clients. > Rather than generate this file and put it in a web dir and tell > clients to download it, is there any way to generate the content > dynamicly and put it to cients? I mean I don't want to generate the > temporary file. Thanks. Hi, Jen. This list is for mod_perl users. It sounds like you are new to web programming, but I could be wrong. I would suggest with a google search for "perl cgi tutorial" and go from there. There is also a beginners-cgi mailing list (not this) and perlmonks.org is a great site for general perl knowledge. Sean
Re: question on downloading CGI
On Fri 05 Sep 2008, [EMAIL PROTECTED] wrote: > I want to generate a data file which should be downloaded by clients. > Rather than generate this file and put it in a web dir and tell > clients to download it, is there any way to generate the content > dynamicly and put it to cients? I mean I don't want to generate the > temporary file. Plenty. For example in your httpd.conf SetHandler modperl PerlResponseHandler "sub { \ use Apache2::RequestRec ();\ use Apache2::RequestIO (); \ use Apache2::Connection ();\ $_[0]->content_type('application/octet-stream'); \ until($_[0]->connection->aborted) {\ $_[0]->print(rand); \ } \ return 0; \ }" Now restart your server and then curl -v http://server/download And you'll get never ending randomness. You can also write a little shell script and use it via mod_cgi: >> the shell script #!/bin/bash echo Content-Type: application/octet-stream echo cat /dev/urandom << end of shell script Now fetch the Apache docs and configure your server to execute the script as CGI program. Remember it is not necessarily faster to send dynamic content this way. Sometimes it is faster to write a temporary file sometime before the response phase and let the default handler send it. If you decide to send the content on the fly try to figure out the content length and set the Content-Length header. This can also improve your performance. Torsten -- Need professional mod_perl support? Just hire me: [EMAIL PROTECTED]
Re: question on downloading CGI
Quoting [EMAIL PROTECTED]: Hello, I want to generate a data file which should be downloaded by clients. Rather than generate this file and put it in a web dir and tell clients to download it, is there any way to generate the content dynamicly and put it to cients? I mean I don't want to generate the temporary file. Thanks. This reads to me like you just want to cause the browser to prompt the user to save the file to disk instead of render the content you are generating in which case you should read about the Content-Disposition header: http://www.ietf.org/rfc/rfc1806.txt The quick summary of which is to add a header to your response that looks like this: Content-Disposition: attachment; filename=filename.extention Adam