[php-src] PR #13041: Fix bug #63937: Upload speed 10 times slower with PHP
| From: | nielsdos | Date: | Wed, 27 Dec 2023 22:35:06 +0000 |
| Subject: | [php-src] PR #13041: Fix bug #63937: Upload speed 10 times slower with PHP | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-24615@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/13041
Author: nielsdos
There are two slow parts in the upload logic:
- Reading from the input stream character by character
- Checking each character one by one to normalize line endings
First of all, the line normalization isn't necessary for binary transfers, so we can use a
simple read while loop to read bytes into the transfer buffer.
Second, for the ASCII transfer where we do have to normalize line endings, we can be smarter than
reading one character at a time. There's a php_stream_get_line() function that we can repurpose
if the flags for the stream are set up properly.
This patch implements these fixes.
Results: I tested this on an 850 MiB file, transferring this to an FTP server running locally.
Results before patch:
Binary/ASCII transfer (same code path): 8.21s
Results after patch:
Binary transfer: 0.65s
ASCII transfer: 0.74s
Further improvement is probably possible by having a larger send buffer.