KnpLabs / Gaufrette

PHP library that provides a filesystem abstraction layer − will be a feast for your files!
http://knplabs.github.io/Gaufrette
MIT License
2.47k stars 355 forks source link

[Ftp] connection succeed but no files found after a certain amount of time / data is exceeded #156

Open iamdto opened 11 years ago

iamdto commented 11 years ago

Using the FTP adapter with passive: true, I recently ran into an issue where the connection looked OK but the call to ftp_nlist in Gaufrette\Adapter\Ftp::exists() failed, returning false.

Before it fails I successfully manage to proceed 60 files.

To be clear :

  1. Everything works fine for the 60 first files (I manage to download them all).
  2. Then a Gaufrette\Exception\FileNotFound is thrown.
  3. Looking at Gaufrette\Adapter\Ftp::exists() I can see that $this->getConnection() returns resource(490) of type (FTP Buffer) (meanings the connection is good, right ?).
  4. However $items is false (whereas it contained files for the 60 first calls).

A temporary workaround is to change the access of Gaufrette\Adapter\Ftp::connect() so it is public, and call it before processing each keys.

But I am not sure it is a good solution.

Someone on the PHP manual also says that in such case we should refresh the connection.

What's your point of view on this one ? Should we add some kind of time out option ?

l3l0 commented 11 years ago

@iamdto Thanks for info. I will try to think how we can fix that... not sure if we can check if reconnect is needed and do it automatically... if not we can do this workaround and make connect method public

iamdto commented 11 years ago

In case we can't check if refresh is needed, I was thinking about an option (called something like limit) which would states the number of calls to getConnection() before the connection is forced.

Something like :

<?php

private function getConnection()
{
    if (!$this->isConnected() || $options['limit'] <= $this->calls) {
        $this->connect();
    }

    return $this->connection;
}

Of course it would be set to null or false by default.

What do you think about that ?

wysow commented 9 years ago

@iamdto Is this still relevant?

iamdto commented 9 years ago

I didn't follow the activity on this project for a long time. I can see that @Zeichen32 PR is closed but not merged. Is there any workaround in the current code that fix this issue? If no, yes it's still relevant.

omansour commented 9 years ago

Hey. It seems I have the same problem.

Fabex commented 8 years ago

Hi, I have exactly the same probleme than every one. After "googleing" I find this : http://grokbase.com/t/php/php-general/142j6a3gcd/testing-php-ftp-connection-if-still-connected

Who explain why "is_resource" is not a good idea.