NYCPHP Meetup

NYPHP.org

[nycphp-talk] can PHP and Perl share a common log file?

Amol Hatwar amol at hatwar.org
Mon Dec 5 15:46:49 EST 2005


On Mon, 2005-12-05 at 13:27 -0500, David Mintz wrote:
> Thought experiment: you are using a Perl module called Log::Trivial
> (http://search.cpan.org/~atrickett/Log-Trivial-0.03/lib/Log/Trivial.pm) to
> log to a file. It uses flock() internally. 

I ain't much of a Perl guru, but flock() is bad for concurrency. For a
lot of simultaneous access you'll be drastically reducing performance.


> You are also using php's native
> error_log() to write to the same log file. Is this asking for trouble?

I guess yes.

> Does log_error() flock() internally, and will it honor a Perl flock()?

No AFAIK, PHP log_error() does an append, but it will honor a Perl
flock() where in lies the problem.

You can have many concurrent appenders without any locking, atomicty is
guranteed courtesy of the file system. But when you have a flock, you
can have only one writer.

So, if your PERL code doesn't release locks soon enough, your PHP code
will wait till the lock is freed, this will unnecessarily reduce
response time. If you can get your Perl code to do an append like PHP,
you'll get atomic updates without the overhead of locking.

What you are suggesting is safe, but at times the contraption may turn
out to be slow.

*chop*

Regards,

ah




More information about the talk mailing list