Skip to content

ext/ftp: Improve FTP_ASCII download performance - #25993

Open
adapik wants to merge 1 commit into
php:masterfrom
adapik:ftp-ascii-download-speed
Open

adapik wants to merge 1 commit into
php:masterfrom
adapik:ftp-ascii-download-speed

Conversation

@adapik

@adapik adapik commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

A small refactoring of ASCII mode downloads, both blocking and non-blocking.

write() syscall was called far too often (ftp_nb_get per byte, ftp_get per line). The CRLF conversion now lives in a helper shared by both paths, which converts each received chunk and writes it at once. This makes downloads much faster.

12.5 MB CRLF file, local server:

Function ASCII before ASCII after Speedup Binary (just for comparison)
ftp_get() 0.026 GB/s 0.63 GB/s ~25x 0.76 GB/s
ftp_nb_get() 0.0015 GB/s 0.57 GB/s ~380x 0.70 GB/s

ASCII mode is probably not widely used nowadays, but it is still supported, and since the problem is fairly obvious and the fix is small, I think it's worth having. I also added a test for non-blocking, this function was only partially covered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant