Dear Monks,
I wrote a small web IMAP client using Mail::IMAPTalk. Everything works fine but I wasn't happy with the fact that I am creating new object of the class IMAP (Mail::IMAPTalk->new()) every time I am dealing with the IMAP server which is why I created a variable which stores the object and queries whether it is fine by using the is_open() method.
The reason for that is that this way I sort of created a persistent link to IMAP server which saved some latency delays which increased the speed of the program dramaticaly.
My setup for this application is simple - I have one index.cgi file which uses application.pm which contains one function main_program and set of shared variables (using "our" declarations). However looks like the variable which I use to store the IMAP object sometime looses it's value and I can't go around this. What is the way to not loose the object and have it in my application? Looks like Apache forks and not all processes has the same copy of this variable? Does that make any sense?
Herewith a sample of the setup I have:
index.cgi file:
use lib "/wwwroot/myimap/"; use myimap; &myimap::myimap;
myimap.pm file:
package myimap;
our $our_cache_imap_object;
sub helpdesk {
if (ENTRY_POINT_FOR_CGI_ACTION...) {
my $imap;
if ( ! exists $our_cache_imap_object ) {
# open the
+ imap connection using IMAP::Talk
$imap = Ma
+il::IMAPTalk->new(
+ Server => $server,
+ Port => $imap_port,
+ Username => $login,
+ Password => $password,
+ Separator => "\\",
+ RootFolder => '',
+ CaseInsensitive => 1,
+ Uid => 1)
+ || die "Connection failed. Reason: $@";
+
+ $our_cache_imap_object = $imap;
+
} elsif ($our_cach
+e_imap_object->is_open()) {
$imap = $our_c
+ache_imap_object;
}
DEAL WITH THE IMAP OBJECT .... ETC.
}
}
1;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.