-
Notifications
You must be signed in to change notification settings - Fork 8.1k
ext/ftp: throw an Error when ftp_nb_fget()/ftp_nb_fput() hit a busy connection #23540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ndossche
merged 4 commits into
php:master
from
lacatoire:fix/ftp-nb-return-types-upstream
Sep 7, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fa921f8
ext/ftp: throw an Error when the connection is already transferring
lacatoire 702ab2a
[skip ci] Note the ftp_nb_fget()/ftp_nb_fput() Error in UPGRADING
lacatoire a738a64
Address review: extend the Error to ftp_nb_get() and ftp_nb_put()
lacatoire 65268c2
Catch Throwable in the re-entrant transfer test
lacatoire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| --TEST-- | ||
| ftp_nb_fget(), ftp_nb_fput(), ftp_nb_get() and ftp_nb_put() throw when a transfer is already in progress | ||
| --EXTENSIONS-- | ||
| ftp | ||
| pcntl | ||
| --FILE-- | ||
| <?php | ||
| require 'server.inc'; | ||
|
|
||
| class TransferDuringNbWrite { | ||
| public $context; | ||
| public static $ftp; | ||
| public static $call; | ||
| public function stream_open($path, $mode, $options, &$opened_path) { | ||
| return true; | ||
| } | ||
| public function stream_write($data) { | ||
| try { | ||
| (self::$call)(self::$ftp); | ||
| } catch (Throwable $e) { | ||
| echo $e::class, ': ', $e->getMessage(), "\n"; | ||
| } | ||
| return strlen($data); | ||
| } | ||
| public function stream_close() {} | ||
| public function stream_eof() { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| stream_wrapper_register('reentrantnb', TransferDuringNbWrite::class); | ||
|
|
||
| $ftp = ftp_connect('127.0.0.1', $port); | ||
| var_dump(ftp_login($ftp, 'user', 'pass')); | ||
| TransferDuringNbWrite::$ftp = $ftp; | ||
|
|
||
| $sink = fopen('php://memory', 'w+'); | ||
| /* ftp_nb_put() opens the local file before it reaches the guard, so it has to exist. */ | ||
| $local = __DIR__ . '/ftp_nb_transfer_during_transfer.tmp'; | ||
| file_put_contents($local, 'payload'); | ||
|
|
||
| $calls = [ | ||
| static fn ($ftp) => ftp_nb_fget($ftp, $sink, 'a story.txt', FTP_BINARY), | ||
| static fn ($ftp) => ftp_nb_fput($ftp, 'a story.txt', $sink, FTP_BINARY), | ||
| static fn ($ftp) => ftp_nb_get($ftp, $local, 'a story.txt', FTP_BINARY), | ||
| static fn ($ftp) => ftp_nb_put($ftp, 'a story.txt', $local, FTP_BINARY), | ||
| ]; | ||
|
|
||
| foreach ($calls as $call) { | ||
| TransferDuringNbWrite::$call = $call; | ||
| @ftp_nb_get($ftp, 'reentrantnb://sink', 'a story.txt', FTP_BINARY); | ||
| } | ||
|
|
||
| ftp_close($ftp); | ||
| echo "closed\n"; | ||
| ?> | ||
| --CLEAN-- | ||
| <?php | ||
| @unlink(__DIR__ . '/ftp_nb_transfer_during_transfer.tmp'); | ||
| ?> | ||
| --EXPECT-- | ||
| bool(true) | ||
| Error: Cannot start a transfer while another transfer is in progress | ||
| Error: Cannot start a transfer while another transfer is in progress | ||
| Error: Cannot start a transfer while another transfer is in progress | ||
| Error: Cannot start a transfer while another transfer is in progress | ||
| closed |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.