Bug #72343 [Com]: SplFileInfo from DirectoryIterator opens new FTP connections

From: Date: Mon, 06 Jun 2016 11:48:49 +0000
Subject: Bug #72343 [Com]: SplFileInfo from DirectoryIterator opens new FTP connections
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-201476@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72343&edit=1 ID: 72343 Comment by: sander at prezent dot nl Reported by: sander at prezent dot nl Summary: SplFileInfo from DirectoryIterator opens new FTP connections Status: Open Type: Bug Package: FTP related Operating System: Linux PHP Version: 7.0.7 Block user comment: N Private report: N New Comment: Related: https://github.com/symfony/symfony/issues/18923 Previous Comments: ------------------------------------------------------------------------ [2016-06-06 11:47:40] sander at prezent dot nl Description: ------------ 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: --------------- <?php // Some public FTP servers to use $ftp = 'ftp://speedtest.tele2.net/'; // Fast server //$ftp = 'ftp://ftp.hq.nasa.gov/'; // 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? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=72343&edit=1

« previous php.bugs (#201476) next »