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

Atomicity of logging to file #1555

Closed
flaushi opened this issue May 18, 2021 · 2 comments
Closed

Atomicity of logging to file #1555

flaushi opened this issue May 18, 2021 · 2 comments
Labels

Comments

@flaushi
Copy link

flaushi commented May 18, 2021

Monolog version 2

I guess the answer to the following question is "yes", but why exactly?

Is logging to a StreamHandler an atomic operation? Can I be sure that if 20 processes do use the same logfile, no lines get mixed up?

I am in a symfony setup, and any php process (or any concurrent request) might send log messages.
How can I be sure that those messages are not e.g. interleaved? In practice I have never encountered problems but I just don't understand why...

Thanks in advance, Olli

@stof
Copy link
Contributor

stof commented May 18, 2021

It depends of the size of the log messages. PHP writes to files in chunks. So if your write logs messages that are bigger than the chunk size (8KiB by default if you don't change your php.ini), it will be split into multiple writes (see #1552 reporting that).

However, separate log messages can be interleaved

@flaushi
Copy link
Author

flaushi commented May 18, 2021

Thanks for your quick answer! So, if not changing the default value and logging just an 80char line I can be sure to not get interleaving. Thanks!

@flaushi flaushi closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants