ankitpokhrel / tus-php

🚀 A pure PHP server and client for the tus resumable upload protocol v1.0.0

Home Page:https://tus.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

File based cache - tus_php.server.cache empty - 410 Error

gianlucacuomo opened this issue · comments

I've installed your server with an Uppy client and tried it in a local and in a staging environments without big issues.
I've just added a couple of lines to manage user based cache and to move the uploads on complete event + some work on the JS side to verify the SHA checksum.

But, at the moment of going live, I had a big issue, all the upload end with a 410 Header and it seems that the server can't write the cache file.

I've tried to move the cachepath in various writable paths and even check if the file is writeble inserting a var_dump in the createCacheFile method.

I've also tried to remove my code per the user based cache and to test it out with the default settings, but still, the cache file is created (as always) but it is never written during uploads.

During my debug it seems that the callback function at line :150 of Cache/FileStore.php is never fired.

All my environments are Apache + PHP 7.3, the only difference between the staging and the production environment is the presence of mod_security2 in the prod env.

Thank you for your hard work

commented

Hi @gianlucacuomo, it is not advised to use FileStore in production. FileStore was initially designed for development purposes and may not work properly in many cases. Please use redis or apcu cache in prod.

From your description it seems like the app is not able to write data to the cache. Default redis and file configuration for server and client can be found inside config/server.php and config/client.php respectively. To override default config you can simply copy the file to your preferred location and update the parameters. You then need to set the config before doing anything else.

\TusPhp\Config::set('<path to your config>');

$server = new \TusPhp\Tus\Server('redis');

Hi @ankitpokhrel, I am having the same issue. We cannot use redis or apcu cache in prod at this moment. I am noticing that the src\cache\FileStore.php is unable to write the cache file. The lock function is not working properly and preventing to write to the cache file.

   protected function lock(string $path, int $type = LOCK_SH, callable $cb = null, $fopenType = FILE::READ_BINARY)
    {
        $out    = false;
        $handle = @fopen($path, $fopenType);

        if (false === $handle) {
            return $out;
        }

        try {
            if (flock($handle, $type)) {
                clearstatcache(true, $path);

                $out = $cb($handle);
            }
        } finally {
            flock($handle, LOCK_UN);
            fclose($handle);
        }

        return $out;
    }

Hi @ankitpokhrel, for now I've switched to another solution because I can't use a different type of cache, but as also @aubrivliz said, the problem wasn't in the cache writing as the library was able to create the file but at the moment of locking it and inserting the content the callback function was never fired.
Thank you

This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.

Closing because of inactivity.