RE: Trouble with sysread in modperl
Title: RE: Trouble with sysread in modperl Stas, We are using Oracle 9iAS (internet application server), it's bundled with the mod_perl version 1.26 (Perl 5.005). I hope this version of mod_perl is okay to use since Oracle will not support if we just upgrade the mod_perl to another version after the installation. Thanks for the suggestion of read_multipart, I will ask our developers to try that out. Regards, Hui -Original Message- From: Stas Bekman [mailto:[EMAIL PROTECTED]] Sent: Saturday, March 08, 2003 11:14 PM To: Liu, Hui (GXS) Cc: [EMAIL PROTECTED] Subject: Re: Trouble with sysread in modperl Liu, Hui (GXS) wrote: Stas, Does this mean read or sysread not work properly in mod_perl and we should stay away from the two functions if we write perl code to work with Apache server? I haven't said that. I doubt so. It could be a bug in your code. I've suggested: I suggest that you look at the implementation of the function read_multipart() in CGI.pm, which does exactly what you want. (I see no reason why not using CGI.pm in first place if you can.) Have you tried that? Also I'm assuming that you are using mod_perl 1.x, right? __ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Trouble with sysread in modperl
Liu, Hui (GXS) wrote: Stas, Yes we tried reading STDIN and it works: while ($readData = STDIN) { $buffer.= $readData; $bufferLength = length($buffer); .. } But it's not working with sysread or read, here are the results for read, the last line is what we expected but it's null: while ($bytesRead = read(STDIN, $buffer, 4096)) { html(bytesRead=[$bytesRead] data=[$buffer]) if ($debug); } Here's the results from the above code : I suggest that you look at the implementation of the function read_multipart() in CGI.pm, which does exactly what you want. (I see no reason why not using CGI.pm in first place if you can.) And please, refrain from posting emails with huge chunks of useless information, in the future. Truncate to keep only the information that may help to understand and reproduce the problem. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
RE: Trouble with sysread in modperl
Title: RE: Trouble with sysread in modperl Stas, Does this mean read or sysread not work properly in mod_perl and we should stay away from the two functions if we write perl code to work with Apache server? Regards, Hui -Original Message- From: Stas Bekman [mailto:[EMAIL PROTECTED]] Sent: Saturday, March 08, 2003 7:09 AM To: Liu, Hui (GXS) Cc: [EMAIL PROTECTED] Subject: Re: Trouble with sysread in modperl Liu, Hui (GXS) wrote: Stas, Yes we tried reading STDIN and it works: while ($readData = STDIN) { $buffer .= $readData; $bufferLength = length($buffer); .. } But it's not working with sysread or read, here are the results for read, the last line is what we expected but it's null: while ($bytesRead = read(STDIN, $buffer, 4096)) { html(bytesRead=[$bytesRead] data="" if ($debug); } Here's the results from the above code : I suggest that you look at the implementation of the function read_multipart() in CGI.pm, which does exactly what you want. (I see no reason why not using CGI.pm in first place if you can.) And please, refrain from posting emails with huge chunks of useless information, in the future. Truncate to keep only the information that may help to understand and reproduce the problem. __ Stas Bekman JAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Trouble with sysread in modperl
Liu, Hui (GXS) wrote: Stas, Does this mean read or sysread not work properly in mod_perl and we should stay away from the two functions if we write perl code to work with Apache server? I haven't said that. I doubt so. It could be a bug in your code. I've suggested: I suggest that you look at the implementation of the function read_multipart() in CGI.pm, which does exactly what you want. (I see no reason why not using CGI.pm in first place if you can.) Have you tried that? Also I'm assuming that you are using mod_perl 1.x, right? __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
RE: Trouble with sysread in modperl
Title: RE: Trouble with sysread in modperl Stas, Yes we tried reading STDIN and it works: while ($readData = STDIN) { $buffer .= $readData; $bufferLength = length($buffer); .. } But it's not working with sysread or read, here are the results for read, the last line is what we expected but it's null: while ($bytesRead = read(STDIN, $buffer, 4096)) { html(bytesRead=[$bytesRead] data="" if ($debug); } Here's the results from the above code : bytesRead=[4096] data=""> Content-Disposition: form-data; name=sessionId SYSTEM-admin-156534-0993 -7d33e41f304f2 Content-Disposition: form-data; name=userId SYSTEM-admin -7d33e41f304f2 Content-Disposition: form-data; name=bankKey RB_AFG -7d33e41f304f2 Content-Disposition: form-data; name=returnTo uploadFileToEnterprise.main -7d33e41f304f2 Content-Disposition: form-data; name=target _top -7d33e41f304f2 Content-Disposition: form-data; name=enterpriseConfName send810Chrysler -7d33e41f304f2 Content-Disposition: form-data; name=uploadFile; filename=D:\webstuff\rbc\Docs\810credit Content-Type: text/plain HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3549 PR|2308|27042.11 VR|1B7GL22N5YS708674|DAKR/C|2000 IR||27042.11|1769.11 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3549 PR|2308|39611.40 VR|1B7KF23Z71J222401|RAMC/Q|2001 IR||39611.40|2591.40 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3549 PR|2308|25377.19 VR|2B4GP2537YR757792|CARAVN|2000 IR||25377.19|1660.19 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3587 PR|2308|30879.13 VR|1B4GP44L7YB689425|GRDCAR|2000 IR||30879.13|2020.13 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|33067.28 VR|1B4GP44L7YB680806|GRDCAR|2000 IR||33067.28|2163.28 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|41202.49 VR|1B4HS28N4YF243809|DURNGO|2000 IR||41202.49|2695.49 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|29377.92 VR|1B7GG22N3YS698862|DAKR/C|2000 IR||29377.92|1921.92 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|42183.68 VR|1B7KF236X1J219823|RAMC/Q|2001 IR||42183.68|2759.68 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|45825.96 VR|1B7KF23651J219504|RAMC/Q|2001 IR||45825.96|2997.96 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|42716.54 VR|1B7KF23661J219494|RAMC/Q|2001 IR||42716.54|2794.54 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|42183.68 VR|1B7KF23681J219822|RAMC/Q|2001 IR||42183.68|2759.68 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|47334.66 VR|1B7MF33621J228921|RAMC/Q|2001 IR||47334.66|3096.66 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|46155.52 VR|1B7MF33791J217374|RAMC/Q|2001 IR||46155.52|3019.52 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|25799.84 VR|2B4GP2534YR748242|CARAVN|2000 IR||25799.84|1687.84 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|31910.61 VR|2C3HH56JXYH323217|INTRED|2000 IR||31910.61|2087.61 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|31910.61 VR|2C3HH56J1YH323218|INTRED|2000 IR||31910.61|2087.61 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3804 PR|2308|28307.92 VR|3B7HC13Y41G193297|RAMC/Q|2001 IR||28307.92|1851.92 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3823 PR|2308|45550.97 VR|1B7KF23611J219659|RAMC/Q|2001 IR||45550.97|2979.97 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3823 PR|2308|49393.34 VR|1B7MF33701J216680|RAM] bytesRead=[4096] data=""> IR||49393.34|3231.34 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3823 PR|2308|28950.99 VR|3B7HC12Y01G193301|RAMC/Q|2001 IR||28950.99|1893.99 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANADA|2479 BR|BANK OF MONTREAL|000124162 DR||3917 PR|2308|38028.87 VR|1B4HS28N0YF233603|DURNGO|2000 IR||38028.87|2487.87 TR HR|810|P||2307|071034|DEBIT MR|CHRYSLER CANAD
Trouble with sysread in modperl
Title: Trouble with sysread in modperl There appears to be a bug with the read and sysread functions when being used in a loop to read STDIN. We're using a loop to read from STDIN in 4k blocks, and the read or sysread appears to work great until the very last read to pick up the final partial block. Here is the code: $readSize = min($bytesLeft, $blockReadSize); $bufferLength = length($buffer); $bytesRead = sysread(STDIN, $dataRead, $readSize); html(bytesRead=[$bytesRead . $bufferLength . $dataRead]) if ($debug); if (!(defined $bytesRead)) { $bytesRead = 0; } $buffer .= $dataRead; In the last loop, the values that are returned in the debug statement are: 674 . 3268 . So sysread says that 674 bytes were read, however $dataRead is empty. Both read and sysread exhibit the same behavior, returning the right number of bytes to be read, but not populating the variable with the actual data. This code works fine in versions of Perl other than Apache modperl. Has anyone experienced this behavior and have any suggestions?
Re: Trouble with sysread in modperl
Hello - There appears to be a bug with the read and sysread functions when being used in a loop to read STDIN. We're using a loop to read from STDIN in 4k blocks, and the read or sysread appears to work great until the very last read to pick up the final partial block. [snip] Not sure about that error, but by any chance are you trying to read POSTed data from the request? If so, all you need to do is: my $content; $r-read($content, $r-header_in('Content-length')); (mod_perl cookbook recipe 3.6) Larry Leszczynski [EMAIL PROTECTED]
RE: Trouble with sysread in modperl
Title: RE: Trouble with sysread in modperl Larry, Thanks for the suggestion. Does this mean if we have a 20MB file, this read will load the entire file into the memory? Regards, Hui Liu -Original Message- From: Larry Leszczynski [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 04, 2003 1:03 PM To: Liu, Hui (GXS) Cc: [EMAIL PROTECTED] Subject: Re: Trouble with sysread in modperl Hello - There appears to be a bug with the read and sysread functions when being used in a loop to read STDIN. We're using a loop to read from STDIN in 4k blocks, and the read or sysread appears to work great until the very last read to pick up the final partial block. [snip] Not sure about that error, but by any chance are you trying to read POSTed data from the request? If so, all you need to do is: my $content; $r-read($content, $r-header_in('Content-length')); (mod_perl cookbook recipe 3.6) Larry Leszczynski [EMAIL PROTECTED]
RE: Trouble with sysread in modperl
Hi Hui Liu - Not sure about that error, but by any chance are you trying to read POSTed data from the request? If so, all you need to do is: my $content; $r-read($content, $r-header_in('Content-length')); (mod_perl cookbook recipe 3.6) Thanks for the suggestion. Does this mean if we have a 20MB file, this read will load the entire file into the memory? Yes, at least up to the size limit defined by POST_MAX. But if you're trying to read uploaded files, don't do it like that. Instead do it like recipe 3.8 which shows how to get a filehandle to the uploaded file, e.g. something like: use Apache::Request; sub handler { my $r = Apache::Request-new(shift, POST_MAX = 20 * 1024 * 1024, DISABLE_UPLOADS = 0); foreach my $upload ($r-upload) { my $fh = $upload-fh; ... } } Larry Leszczynski [EMAIL PROTECTED]
RE: Trouble with sysread in modperl
Title: RE: Trouble with sysread in modperl Larry, Thank you. I wonder which Mod_perl cook book you are referring to and where can we get them? I am very interested in details of recipe 3.8. This is our first time to port our perl scripts to Apache (we are using Apache:PerRun mode), and we are still learning. Thanks and Regards, Hui Liu -Original Message- From: Larry Leszczynski [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 04, 2003 3:16 PM To: Liu, Hui (GXS) Cc: mod_perl list Subject: RE: Trouble with sysread in modperl Hi Hui Liu - Not sure about that error, but by any chance are you trying to read POSTed data from the request? If so, all you need to do is: my $content; $r-read($content, $r-header_in('Content-length')); (mod_perl cookbook recipe 3.6) Thanks for the suggestion. Does this mean if we have a 20MB file, this read will load the entire file into the memory? Yes, at least up to the size limit defined by POST_MAX. But if you're trying to read uploaded files, don't do it like that. Instead do it like recipe 3.8 which shows how to get a filehandle to the uploaded file, e.g. something like: use Apache::Request; sub handler { my $r = Apache::Request-new(shift, POST_MAX = 20 * 1024 * 1024, DISABLE_UPLOADS = 0); foreach my $upload ($r-upload) { my $fh = $upload-fh; ... } } Larry Leszczynski [EMAIL PROTECTED]
mod_perl books (Was: RE: Trouble with sysread in modperl)
Hi Hui Liu - Larry, Thank you. I wonder which Mod_perl cook book you are referring to and where can we get them? I am very interested in details of recipe 3.8. This is our first time to port our perl scripts to Apache (we are using Apache:PerRun mode), and we are still learning. The best overall online resource is the mod_perl web site at: http://perl.apache.org/ Books related to mod_perl, including the mod_perl Developer's Cookbook, are listed at: http://perl.apache.org/docs/offsite/books.html Larry Leszczynski [EMAIL PROTECTED]
Re: mod_perl books (Was: RE: Trouble with sysread in modperl)
Hi all, my name is Jordan and I've been monitoring this discussion group learning slowly how apache and mod_perl works. though I've rarely ever posted any questions or concerns regarding my configurations, I found that this discussion group has provided many answers to my multitude of questions. I just wanted to say thanks, you've all been a great help :-) ~jordan - Original Message - From: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: mod_perl list [EMAIL PROTECTED] Sent: Tuesday, March 04, 2003 3:39 PM Subject: Re: mod_perl books (Was: RE: Trouble with sysread in modperl) Hi Hui Liu You can start from http://perl.apache.org/docs/2.0/user/intro/start_fast.pdf instead of reading the very thick books. You can google to find out example codes as well. Gook Luck, Huili Liu Larry Leszczynski [EMAIL PROTECTED]To: Liu, Hui (GXS) [EMAIL PROTECTED] cc: mod_perl list [EMAIL PROTECTED] Subject: mod_perl books (Was: RE: Trouble with sysread in modperl) 03/04/2003 03:40 PM Please respond to Larry Leszczynski Hi Hui Liu - Larry, Thank you. I wonder which Mod_perl cook book you are referring to and where can we get them? I am very interested in details of recipe 3.8. This is our first time to port our perl scripts to Apache (we are using Apache:PerRun mode), and we are still learning. The best overall online resource is the mod_perl web site at: http://perl.apache.org/ Books related to mod_perl, including the mod_perl Developer's Cookbook, are listed at: http://perl.apache.org/docs/offsite/books.html Larry Leszczynski [EMAIL PROTECTED]
RE: mod_perl books (Was: RE: Trouble with sysread in modperl)
Title: RE: mod_perl books (Was: RE: Trouble with sysread in modperl) Larry and Huili, Thank you very much for the information and all your help. I just ordered a book called mod_perl Developer's Cookbook by Geoffrey Young, et al. from Amazon.com. I hope we will go from there. Regards, Hui Liu -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 04, 2003 3:40 PM To: Liu, Hui (GXS) Cc: mod_perl list Subject: Re: mod_perl books (Was: RE: Trouble with sysread in modperl) Hi Hui Liu You can start from http://perl.apache.org/docs/2.0/user/intro/start_fast.pdf instead of reading the very thick books. You can google to find out example codes as well. Gook Luck, Huili Liu Larry Leszczynski [EMAIL PROTECTED] To: Liu, Hui (GXS) [EMAIL PROTECTED] cc: mod_perl list [EMAIL PROTECTED] Subject: mod_perl books (Was: RE: Trouble with sysread in modperl) 03/04/2003 03:40 PM Please respond to Larry Leszczynski Hi Hui Liu - Larry, Thank you. I wonder which Mod_perl cook book you are referring to and where can we get them? I am very interested in details of recipe 3.8. This is our first time to port our perl scripts to Apache (we are using Apache:PerRun mode), and we are still learning. The best overall online resource is the mod_perl web site at: http://perl.apache.org/ Books related to mod_perl, including the mod_perl Developer's Cookbook, are listed at: http://perl.apache.org/docs/offsite/books.html Larry Leszczynski [EMAIL PROTECTED]
Re: Trouble with sysread in modperl
Liu, Hui (GXS) wrote: There appears to be a bug with the read and sysread functions when being used in a loop to read STDIN. We're using a loop to read from STDIN in 4k blocks, and the read or sysread appears to work great until the very last read to pick up the final partial block. Here is the code: $readSize = min($bytesLeft, $blockReadSize); $bufferLength = length($buffer); $bytesRead = sysread(STDIN, $dataRead, $readSize); html(bytesRead=[$bytesRead . $bufferLength . $dataRead]) if ($debug); if (!(defined $bytesRead)) { $bytesRead = 0; } $buffer .= $dataRead; In the last loop, the values that are returned in the debug statement are: 674 . 3268 . So sysread says that 674 bytes were read, however $dataRead is empty. Both read and sysread exhibit the same behavior, returning the right number of bytes to be read, but not populating the variable with the actual data. This code works fine in versions of Perl other than Apache modperl. Has anyone experienced this behavior and have any suggestions? Could it be the buffering issue as described in the manpage? perldoc -f sysread: sysread FILEHANDLE,SCALAR,LENGTH,OFFSET sysread FILEHANDLE,SCALAR,LENGTH Attempts to read LENGTH characters of data into variable SCALAR from the specified FILEHANDLE, using the system call read(2). It bypasses buffered IO, so mixing this with other kinds of reads, print, write, seek, tell, or eof can cause confusion because stdio usually buffers data. Returns the num- ber of characters actually read, 0 at end of file, or undef if there was an error. SCALAR will be grown or shrunk so that the last byte actually read is the last byte of the scalar after the read. [...] can you try whether you get all the data, by reading via STDIN (even though you have no control over chunks size) __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com