RE: Trouble with sysread in modperl

2003-03-10 Thread Liu, Hui (GXS)
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

2003-03-08 Thread Liu, Hui (GXS)
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

2003-03-05 Thread Liu, Hui (GXS)
6725.39|1748.39
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||8647
PR|2308|32055.06
VR|1B7KC23Z51J231686|RAMC/Q|2001
IR||32055.06|2097.06
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||8647
PR|2308|32055.06
VR|1B7KC23Z71J231687|RAMC/Q|2001
IR||32055.06|2097.06
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||8647
PR|2308|46553.56
VR|1B7KF23691J221756|RAMC/Q|2001
IR||46553.56|3045.56
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||8647
PR|2308|21835.49
VR|1C3ES46C1YD760102|NEON|2000
IR||21835.49|1428.49
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||9029
PR|2308|26526.37
VR|1B4GP44L0YB683238|GRDCAR|2000
IR||26526.37|1735.37
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||9029
PR|2308|26526.37
VR|1B4GP44L8YB689997|GRDCAR|2000
IR||26526.37|1735.37
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||9303
PR|2308|26494.27
VR|1B4GP44LXYB689175|GRDCAR|2000
IR||26494.27|1733.27
TR
HR|810|P||2307|071034|CREDIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||9303
PR|2308|42457.60
VR|1B4HS28N5YF198654|DURNGO|2000
IR||42457.60|2777.60
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||9303
PR|2308|35740.14
VR|1B7HF13Z91J213798|RAMC/Q|2001
IR||35740.14|2338.14
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||9303
PR|2308|22166.12
VR|1C3ES46CXYD776637|NEON|2000
IR||22166.12|1450.12
TR
HR|810|P||2307|071034|DEBIT
MR|CHRYSLER CANADA|2479
BR|BANK OF MONTREAL|000124162
DR||9303
PR|2308|22166.12
VR|1C3ES46CXYD776640|NEON|2000
IR||22166.12|1450]
bytesRead=[692] data="">




-Original Message-
From: Stas Bekman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 04, 2003 5:54 PM
To: Liu, Hui (GXS)
Cc: [EMAIL PROTECTED]
Subject: 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 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





Trouble with sysread in modperl

2003-03-04 Thread Liu, Hui (GXS)
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

2003-03-04 Thread Liu, Hui (GXS)
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

2003-03-04 Thread Liu, Hui (GXS)
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]





RE: mod_perl books (Was: RE: Trouble with sysread in modperl)

2003-03-04 Thread Liu, Hui (GXS)
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]