Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for log file locking #384

Merged
merged 1 commit into from Jul 28, 2014
Merged

Conversation

bobrik
Copy link
Contributor

@bobrik bobrik commented Jun 30, 2014

Closes #379.

Not sure how to test failing flock. Any ideas?

@bobrik
Copy link
Contributor Author

bobrik commented Jul 8, 2014

I've fixed bad test, btw.

@Seldaek
Copy link
Owner

Seldaek commented Jul 28, 2014

Thanks!

@Seldaek Seldaek merged commit 6c799b3 into Seldaek:master Jul 28, 2014
@mta59066
Copy link

Locking for who? Flock is an advisory lock and does not enforce anything. It is only useful if you look for it. So what this does is place an advisory lock on the file against other possible writers who might check for this lock.

It does not do anything about #379 and the existence of it gives the false assumption that there is a locking mechanism between different processes utilizing monolog.

@stof
Copy link
Contributor

stof commented Jan 21, 2019

hmm indeed. Ignoring the locking error makes the locking useless to solve the issue. But please open an issue instead of commenting on a 4.5 year old merged PR. Most people won't ever look at it.

@IMSoP
Copy link

IMSoP commented Jul 30, 2020

@mta59066 (and anyone else that comes upon this comment) The lock is "advisory" in terms of code that never requests a lock, but it is still blocking for all code that does request a lock. If you have two instances of the same code, and both call flock, one process will be forced to wait until the other process releases the lock. That should be enough to stop two log messages interrupting each other in the same file.

You can demonstrate this for yourself with a simple test script like this:

$fh = fopen('/tmp/example.log', 'a');
echo getmypid(), " acquiring lock...\n";
flock($fh, LOCK_EX);
echo getmypid(), " lock acquired; sleeping for 10 seconds...\n";
sleep(10);
echo getmypid(), " releasing lock...\n";
flock($fh, LOCK_UN);
echo getmypid(), " done.\n";

Running that 3 times gives the following output:

3458 acquiring lock...
3458 lock acquired; sleeping for 10 seconds...
3468 acquiring lock...
3475 acquiring lock...
3458 releasing lock...
3458 done.
3475 lock acquired; sleeping for 10 seconds...
3475 releasing lock...
3475 done.
3468 lock acquired; sleeping for 10 seconds...
3468 releasing lock...
3468 done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parallel logging interference (I assume)
5 participants