On Mon, Mar 10, 2008 at 10:08 AM, Jonathan Mast
<[EMAIL PROTECTED]> wrote:
> We have a socket server that, in addition to serving data, also writes
>  logging statements to a file.
>
>  My question concerns the correctness of how it accesses the log file.  The
>  script is running continuously and all the log file IO stuff is inside the
>  main 'while' loop.
>  The file is opened, written to and closed during each iteration of the
>  loop.  This seems very inefficient to me, all the opening and closings I
>  presume are IO intensive.
>  Would placing the opening and closing of the filehandle outside the while
>  loop be a good idea?
snip

There are benefits and drawbacks to each method.  In general I favor a
lock, open, write, close, unlock pattern because it offers the most
protection (multiple servers can use the same log, the log can be
rotated out from under the running process, etc); however, if you have
a large amount of logging data you may wish to use a log server
instead.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to