libapa...uestIO(3pm)
π NAME π
Apache2::RequestIO β the Perl API for doing IO on the Apache request record. Yes bestie, this is the one that lets you talk to the client. (Fun fact: this page lives in the libapa...uestIO(3pm) manual, 3pm section, and honestly the truncated filename is iconic. π)
πΈ SYNOPSIS πΈ
use Apache2::RequestIO ();
$rc = $r->discard_request_body();
$r->print("foo", "bar");
$r->puts("foo", "bar"); # same as print, but no flushing
$r->printf("%s $d", "foo", 5);
$r->read($buffer, $len);
$r->rflush();
$r->sendfile($filename);
$r->write("foobartarcar", 3, 5);
π¦ DESCRIPTION π¦
Apache2::RequestIO is the whole vibe: it provides the API you use to perform IO on the Apache request object. That's the assignment. Periodt. β¨
π API π
Apache2::RequestIO provides the following functions and/or methods, and we're going through every single one, no skips, no skimming:
π discard_request_body
Ok so listen. In HTTP/1.1, any method can have a body. But most GET handlers would be like "girl what do I do with this request body??" if one showed up. This helper routine tests for and reads any message body in the request, and justβ¦ simply discards whatever it receives. π
We need to do this because failing to read the request body would cause it to be interpreted as the next request on a persistent connection β and that's not a cute look.
$rc = $r->discard_request_body();
- obj:
$r(Apache2::RequestRec object) β the current request. - ret:
$rc( integer ) β anAPR::Const status constantif the request is malformed,Apache2::Const::OKotherwise. - since: 2.0.00
Since we return an error status if the request is malformed, this routine should be called at the beginning of a no-body handler, like:
use Apache2::Const -compile => qw(OK);
$rc = $r->discard_request_body;
return $rc if $rc != Apache2::Const::OK;
π print
Send data to the client. Slay.
$cnt = $r->print(@msg);
- obj:
$r(Apache2::RequestRec object) - arg1:
@msg( ARRAY ) β data to send. - ret:
$cnt( number ) β how many bytes were sent (or buffered). Careful: if zero bytes were sent,printwill return0E0, aka "zero but true," which will still evaluate to 0 in a numerical context. Sneaky little thing. π - excpt:
APR::Error - since: 2.0.00
The data is flushed only if STDOUT stream's $| is true. Otherwise it's buffered up to the size of the buffer, flushing only excessive data.
π printf
Format and send data to the client (same as printf).
$cnt = $r->printf($format, @args);
- obj:
$r(Apache2::RequestRec object) - arg1:
$format( string ) β the format string, as in the Perl coreprintffunction. - arg2:
@args( ARRAY ) β the arguments to be formatted, as in the Perl coreprintffunction. - ret:
$cnt( number ) β how many bytes were sent (or buffered). - excpt:
APR::Error - since: 2.0.00
The data is flushed only if STDOUT stream's $| is true. Otherwise it's buffered up to the size of the buffer, flushing only excessive data.
π§ puts
Send data to the client.
$cnt = $r->puts(@msg);
- obj:
$r(Apache2::RequestRec object) - arg1:
@msg( ARRAY ) β data to send. - ret:
$cnt( number ) β how many bytes were sent (or buffered). - excpt:
APR::Error - since: 2.0.00
puts() is similar to print(), but it won't attempt to flush data, no matter what the value of STDOUT stream's $| is. So assuming STDOUT stream's $| is true, this method should be a tiny bit faster than print(), especially if small strings are printed. Tiny little performance glow-up. β¨
π read
Read data from the client.
$cnt = $r->read($buffer, $len);
$cnt = $r->read($buffer, $len, $offset);
- obj:
$r(Apache2::RequestRec object) - arg1:
$buffer( SCALAR ) β the buffer to populate with the read data. - arg2:
$len( number ) β how many bytes to attempt to read. - opt arg3:
$offset( number ) β if a non-zero$offsetis specified, the read data will be placed at that offset in the$buffer.
META: negative offset and \0 padding are not supported at the moment. Not me pointing out the limitation, but like, someone had to. π
- ret:
$cnt( number ) β how many characters were actually read. - excpt:
APR::Error - since: 2.0.00
This method shares a lot of similarities with the Perl core read() function. The main difference is in the error handling, which is done via APR::Error exceptions.
π rflush
Flush any buffered data to the client.
$r->rflush();
- obj:
$r(Apache2::RequestRec object) - ret: no return value
- since: 2.0.00
Unless STDOUT stream's $| is false, data sent via $r->print() is buffered. This method flushes that data to the client. Very "let it out, bestie" of it. π«Ά
β sendfile
Send a file, or a part of it.
$rc = $r->sendfile($filename);
$rc = $r->sendfile($filename, $offset);
$rc = $r->sendfile($filename, $offset, $len);
- obj:
$r(Apache2::RequestRec object) - arg1:
$filename( string ) β the full path to the file (using/on all systems). - opt arg2:
$offset( integer ) β offset into the file to start sending. No offset is used if$offsetis not specified. - opt arg3:
$len( integer ) β how many bytes to send. If not specified the whole file is sent (or a part of it, if$offsetis specified). - ret:
$rc(APR::Const status constant) β on success,APR::Const::SUCCESSis returned. In case of a failure β a failure code is returned, in which case normally it should be returned to the caller. - excpt:
APR::Errorβ exceptions are thrown only when this function is called in the VOID context. So if you don't want to handle the errors, just don't ask for a return value and the function will handle all the errors on its own. Main character energy: it handles its own problems. π - since: 2.0.00
π₯ write
Send a partial string to the client.
$cnt = $r->write($buffer);
$cnt = $r->write($buffer, $len);
$cnt = $r->write($buffer, $len, $offset);
- obj:
$r(Apache2::RequestRec object) - arg1:
$buffer( SCALAR ) β the string with data. - opt arg2:
$len( SCALAR ) β how many bytes to send. If not specified, or-1is specified, all the data in$buffer(or starting from$offset) will be sent. - opt arg3:
$offset( number ) β offset into the$bufferstring. - ret:
$cnt( number ) β how many bytes were sent (or buffered). - excpt:
APR::Error - since: 2.0.00
β¨ Examples β¨
Assuming that we have a string:
$string = "123456789";
Then:
$r->write($string);
sends:
123456789
Whereas:
$r->write($string, 3);
sends:
123
And:
$r->write($string, 3, 5);
sends:
678
Finally:
$r->write($string, -1, 5);
sends:
6789
π TIE INTERFACE π
The TIE interface implementation. This interface is used for HTTP request handlers, when running under SetHandler perl-script and Perl doesn't have perlio enabled.
See the perltie manpage for more information.
π¦ BINMODE
- since: 2.0.00
NoOP.
See the binmode Perl entry in the perlfunc manpage.
π¦ CLOSE
- since: 2.0.00
NoOP.
See the close Perl entry in the perlfunc manpage.
π¦ FILENO
- since: 2.0.00
See the fileno Perl entry in the perlfunc manpage.
π¦ GETC
- since: 2.0.00
See the getc Perl entry in the perlfunc manpage.
π¦ OPEN
- since: 2.0.00
See the open Perl entry in the perlfunc manpage.
π¦ PRINT
- since: 2.0.00
See the print Perl entry in the perlfunc manpage.
π¦ PRINTF
- since: 2.0.00
See the printf Perl entry in the perlfunc manpage.
π¦ READ
- since: 2.0.00
See the read Perl entry in the perlfunc manpage.
π¦ TIEHANDLE
- since: 2.0.00
See the tie Perl entry in the perlfunc manpage.
π¦ UNTIE
- since: 2.0.00
NoOP.
See the untie Perl entry in the perlfunc manpage.
π¦ WRITE
- since: 2.0.00
See the write Perl entry in the perlfunc manpage.
π DEPRECATED API π
Ok bestie, listen carefully: the following methods are deprecated. Apache plans to remove those in the future, therefore avoid using them. Like, don't. This is your warning. π«
π get_client_block
This method is deprecated since the C implementation is buggy and we don't want you to use it at all. Instead use the plain $r->read(). That's the good one. Use that one.
π setup_client_block
This method is deprecated since $r->get_client_block is deprecated. (Chain reaction of nope.)
π should_client_block
This method is deprecated since $r->get_client_block is deprecated. (Same energy, same nope.)
π SEE ALSO π
mod_perl 2.0 documentation. Go read it, it's right there. π
π COPYRIGHT π
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.
π«Ά AUTHORS π«Ά
The mod_perl development team and numerous contributors. Legends, all of them. π
And that's a wrap, bestie!! πβ¨ This iconic little number is from perl v5.42.3, dated 2026-08-20, and it lives in the libapa...uestIO(3pm) manual β go forth and do your request IO, you've got this. π
π¦πΈ
π¦ where this page comes from
- ubuntu stonking: libapache2-mod-perl2 2.0.13-2build3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms