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

zlib streams should support locking #17668

Open
githubyiti opened this issue Feb 2, 2025 · 8 comments
Open

zlib streams should support locking #17668

githubyiti opened this issue Feb 2, 2025 · 8 comments

Comments

@githubyiti
Copy link

Description

The following code:

<?php
			$gz = gzopen($cachefileb,'w9');
			gzwrite($gz, $towrite);
			gzclose($gz);

Resulted in this output:
Current function caused disk error while multiple sessions is writing to the same file.

But I expected this output instead:
can the file be locked while the file is being written?

### PHP Version

PHP 7.4

### Operating System

Almalinux
@cmb69
Copy link
Member

cmb69 commented Feb 2, 2025

@githubyiti
Copy link
Author

Thanks for the response!
Yes, someone is reporting the same problem on exactly the page you gave, has the issue been solved?
https://www.php.net/flock#111443

@cmb69
Copy link
Member

cmb69 commented Feb 2, 2025

No, that issue still persists. From a quick look at the implementation, the actual file stream is an "inner stream".

Workaround: use fopen() instead of gzopen() (and use ini_set("zlib.output_compression", 9")).

PS: probably better anyway: use a separate lock file (.lck).

@githubyiti
Copy link
Author

Thanks.

The old code in use has already created a lot of data, fear rewriting the old code may unexpectly corrupt the old data.
new scripts are using the way you suggested.

Hope if can have something like gz_lock to patch to the old code.

Regards,

@cmb69
Copy link
Member

cmb69 commented Feb 2, 2025

This cannot be implemented for PHP < 8.5, and I would assume that upgrading to PHP 8 already requires quite some changes to your code base, so possibly tough luck.

Anyway, let's turn this into a proper feature request, since it generally makes sense to be able to lock zlib streams.

@cmb69 cmb69 changed the title How to lock file when gzwrite file? zlib streams should support locking Feb 2, 2025
@cmb69
Copy link
Member

cmb69 commented Feb 2, 2025

Implementation would need to start at

NULL /* set_option */

@githubyiti
Copy link
Author

Thanks for moderating the title.
Hope will have gz_lock in the future.

@cmb69
Copy link
Member

cmb69 commented Feb 2, 2025

Hope will have gz_lock in the future.

Well, you would rather be able to use flock().

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

No branches or pull requests

2 participants