|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72343 FTP wrapper should re-use connections
Submitted: 2016-06-06 11:47 UTC Modified: 2021-02-04 17:57 UTC
Avg. Score:3.7 ± 1.9
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: sander at prezent dot nl Assigned:
Status: Open Package: Streams related
PHP Version: 7.0.7 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: sander at prezent dot nl
New email:
PHP Version: OS:


 [2016-06-06 11:47 UTC] sander at prezent dot nl
Iterating over an FTP directory using \DirectoryIterator and then using the \SplFileInfo is extremely slow. Methods called un the \SplFileInfo object, such as `isDir()` and `isFile()` cause PHP to open a new FTP connection under the hood for every file to retrieve file information.

This issue becomes more apparent when an FTP server is slow during authentication.

Test script:

// Some public FTP servers to use
$ftp = ''; // Fast server
//$ftp = '';     // Not so fast server

echo "Testing on $ftp\n";

$it = new NoRewindIterator(new DirectoryIterator($ftp));

foreach ($it as $file) {
    var_dump($file->isFile()); // This causes new connections and the slowdown

Expected result:
No constant stream of new FTP connections and better performance. The FTP extension should reuse the connection that was established with the \DirectoryIterator.

Also, since \DirectoryIterator already gets an FTP file listing, it probably already knows what it should respond to isFile()/isDir() and other \SplFileInfo method calls. Can that information not simply be reused?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-06 11:48 UTC] sander at prezent dot nl
 [2021-02-04 17:57 UTC]
-Summary: SplFileInfo from DirectoryIterator opens new FTP connections +Summary: FTP wrapper should re-use connections -Type: Bug +Type: Feature/Change Request -Package: FTP related +Package: Streams related
 [2021-02-04 17:57 UTC]
This is not particularly related to SPL, but rather is general
limitation of the FTP protocol wrapper which does not re-use
opened connections.  You see the same bad performance when using
the standard file/dir functions (i.e. opendir()/readdir() and

Basically, what stof already said[1].

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 12 21:01:32 2024 UTC