Gaufrette icon indicating copy to clipboard operation
Gaufrette copied to clipboard

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

Open iamdto opened this issue 11 years ago • 6 comments

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 ?

iamdto avatar Mar 19 '13 17:03 iamdto

@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

l3l0 avatar Mar 20 '13 11:03 l3l0

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 ?

iamdto avatar Mar 20 '13 13:03 iamdto

@iamdto Is this still relevant?

wysow avatar Mar 04 '15 17:03 wysow

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.

iamdto avatar Mar 04 '15 18:03 iamdto

Hey. It seems I have the same problem.

omansour avatar Mar 27 '15 12:03 omansour

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.

Fabex avatar Jun 13 '16 13:06 Fabex