Skip to content

Conversation

@NathanFreeman
Copy link
Contributor

@NathanFreeman NathanFreeman commented Oct 26, 2025

Hello everyone, I plan to add coroutine support for FTP in Swoole. However, in the current FTP implementation, the use of poll is hardcoded, which lacks flexibility and makes it impossible to coroutine-enable FTP in Swoole. Therefore, I have made the following modifications to the my_poll function in ftp.c:

  1. Replaced the direct call to php_pollfd_for_ms with a function pointer named php_ftp_pollfd_for_ms.
  2. During the extension initialization phase, the pointer is set to point to the original php_pollfd_for_ms implementation by default, ensuring the existing synchronous logic remains unaffected.
  3. When running in a coroutine environment, this function pointer can be replaced with a coroutine-compatible polling function (such as a non-blocking version based on an event loop), thereby achieving non-blocking FTP socket operations for the main thread.

This modification does not affect the original FTP logic and introduces no syntactic changes.

With this change, I can easily assign a value to php_ftp_pollfd_for_ms in my own extension, enabling coroutine support for FTP without any disruptive intrusions into the FTP code.

swoole pr:swoole/swoole-src#5899

@NathanFreeman NathanFreeman changed the title Make the FTP extension coroutine-enabled [WIP]Make the FTP extension coroutine-enabled Oct 26, 2025
@NathanFreeman
Copy link
Contributor Author

But I'm not very familiar with the PHP compilation process on Windows and have encountered the following issue. Could this be due to a step I might have missed? Thank you!

ftp.obj : error LNK2019: unresolved external symbol __imp_php_ftp_pollfd_for_ms referenced in function my_poll
php_ftp.obj : error LNK2001: unresolved external symbol __imp_php_ftp_pollfd_for_ms
C:\obj\Release_TS\php_ftp.dll : fatal error LNK1120: 1 unresolved externals

windows error: https://github.com/php/php-src/actions/runs/18814180127/job/53680051090?pr=20299

@kallesommernielsen
Copy link
Member

@NathanFreeman take a look at ext/enchant, specifically PHP_ENCHANT_API should be an example of how an extension can export its symbols. Hope it helps

@NathanFreeman
Copy link
Contributor Author

@kallesommernielsen Thank you, I'll give it a try.

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.

2 participants