indeyets/appserver-in-php

Failed to flush session data

xrstf opened this issue · 3 comments

I'm trying to use AiP with Windows (of course not as a real application server). For this my mod_php will just fire up a PHP script that sets up the autoloading, instantiates my app server class (the same AiP would fire up) and invoke it with some context data.

This works really well, except for the sessions. Sessions cannot be saved and I get the PHP error

Warning: file_put_contents(): Only 0 of 85 bytes written, possibly out of free disk space

Disk space is OK. I can write to the file in question without any problems. Even from PHP, even from the same script and same request. The problem is the file locking, which uses LOCK_EX. If I add LOCK_SH, session files are written and the problem goes away.

<?
// AiP/Middleware/Session/Storage/FileStorage.php, line 140
flock($this->_fp, LOCK_EX | LOCK_SH);

I'm no expert on file locking, so I can't recommend this as a general solution (that's why I didn't create a pull request). If however it's no problem for *nix systems to have the LOCK_SH flag set, I would greatly appreciate having it in there.

In the meantime, I just use a patched version for Windows systems. Since I cannot use Composer to install AiP (requires posix and pcntl extensions), I have to install the vendor stuff by extracting a zip file anyway. So it's not super urgent to be fixed.

regarding LOCK_SH — I'll check that, thanks.

p.s. posix/pcntl stuff should probably be extracted to the separate package. it's needed only for the CLI-tool

Can you check if commit above fixes your issues?

Yes, your changes fix the problems on Windows. :-)