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

Saving models to PHAR file results in error #340

Open
nviet opened this issue Jun 22, 2024 · 1 comment
Open

Saving models to PHAR file results in error #340

nviet opened this issue Jun 22, 2024 · 1 comment

Comments

@nviet
Copy link

nviet commented Jun 22, 2024

Hi there. First of all I'd like to thank you for this library as I have been playing with it to learn Machine Learning for quite some time.

So today I wanted to save the models to a PHAR file, I tried this:

$persister = new Filesystem("phar://model.phar/model.rbx", false);
$serializer = new RBX(6);
$encoding = $serializer->serialize($persistable);
$persister->save($encoding);

Then I got the Exception message Could not write to the filesystem. The reason is because of this line in the file Persisters/Filesystem.php:

$success = file_put_contents($this->path, $encoding->data(), LOCK_EX);

The flag LOCK_EX can only be used if the file is within local filesystem (the file wrapper must start with file://). Other than that, PHP will throw a warning message Exclusive locks may only be set for regular files as defined in its source code file.c.

So if anyone tries to save the models to other file wrappers such as http:// or ftp://, it will not success too.

@andrewdalpino
Copy link
Member

Hey @nviet thanks for the great report!

The reason for the LOCK_EX i.e. exclusive lock is to prevent another process from writing to the file at the same time a model is being saved for example. This is an edge case for many people, but may come into play for some.

What if we made locking an argument of the constructor instead of hardcoding it to on? Would that solve the problem in your case?

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

No branches or pull requests

2 participants