Skip to content

Conversation

@ArtKoKo
Copy link

@ArtKoKo ArtKoKo commented Nov 20, 2025

Summary

This PR includes two changes:

  1. php-openswoole (new port): High-performance network framework for PHP

    • Supports PHP 8.0 through 8.4
    • Version 25.2.0 for PHP 8.2+
    • Version 22.1.2 for PHP 8.1
    • Version 4.11.1 for PHP 8.0
    • Fork of Swoole with additional features
    • Properly declares conflicts with php-swoole
  2. php-swoole (existing port): No changes, maintained for reference

Testing

  • Portfile syntax validated with port lint
  • Checksums verified for all versions
  • Conflicts properly declared between swoole and openswoole
  • Dependencies verified

Notes

  • OpenSwoole must load after the sockets extension (handled via php.extension_ini)
  • Both extensions cannot be installed simultaneously (mutual conflicts)
  • OpenSwoole includes additional features: brotli and c-ares (v22.0.0+)
Type(s)
  • bugfix
  • enhancement
  • security fix
Tested on

macOS 15.7.2 24G325 arm64
Command Line Tools 26.1.0.0.1.1761104275

Verification

Have you

  • followed our Commit Message Guidelines?
  • squashed and minimized your commits?
  • checked that there aren't other open pull requests for the same change?
  • referenced existing tickets on Trac with full URL in commit message?
  • checked your Portfile with port lint?
  • tried existing tests with sudo port test?
  • tried a full install with sudo port -vst install?
  • tested basic functionality of all binary files?
  • checked that the Portfile's most important variants haven't been broken?

    - php-swoole: maintained existing version branches
    - php-openswoole: add new port with support for PHP 8.0-8.4
    - php-openswoole: version 25.2.0 for PHP 8.2+
    - php-openswoole: version 22.1.2 for PHP 8.1
    - php-openswoole: version 4.11.1 for PHP 8.0
    - both ports have mutual conflicts declared
@macportsbot
Copy link

Notifying maintainers:
@ryandesign for port php-openswoole, php-swoole.

@BjarneDMat
Copy link
Contributor

duplicate of work in #28140

@ArtKoKo
Copy link
Author

ArtKoKo commented Nov 21, 2025

Not really, the same work for openswoole with the dependencies...

BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Nov 22, 2025
@BjarneDMat
Copy link
Contributor

So, I implemented your work in my PR28140
I've got the following Questions/Issues:

  1. Why have you dropped support for php7x ? I know, that @ryandesign will want to keep it
  2. Why version 4.11.1 for php80 instead of 22.0.0 ?

I've tested on my platforms :

Model Identifier: Macmini6,1                Model Identifier: MacPro5,1
macOS 10.15.7 19H2026 x86_64                macOS 15.7.1 24G231 x86_64
Xcode 12.4 12D4e                            Xcode 26.0.1 17A400
Command Line Tools 12.4.0.0.1.1610135815    Command Line Tools 26.0.0.0.1.1757719676

and have got this :

$=> port -q installed | awk '/php..-openswoole/'
  php74-openswoole @22.0.0_1 (active)
  php80-openswoole @22.0.0_1 (active)
  php81-openswoole @22.1.2_0 (active)
  php82-openswoole @25.2.0_0 (active)
  php83-openswoole @25.2.0_0 (active)
  php84-openswoole @25.2.0_0 (active)

php85-openswoole fails to compile - see openswoole/ext-openswoole#379

@ArtKoKo
Copy link
Author

ArtKoKo commented Nov 22, 2025

  1. Yes, that was a mistake. My initial goal was for OpenSwoole to work with php84 locally. It was only later that I decided to share my work, but I remember why I erase this lines :
  • Official end of life: PHP 7.2 and 7.3 are no longer supported by the PHP team and no longer receive security updates.
  • Security priority: OpenSwoole emphasizes security (the very reason for the fork from Swoole), so maintaining versions for obsolete PHP versions would be contradictory.
  • Official announcement: Starting with version 4.8.0, the OpenSwoole team announced the end of support for PHP 7.2/7.3 following community feedback.
  • Effective removal: Versions 4.11.0 and 4.12.0 officially removed PHP 7.2/7.3, recommending PHP 7.4.32, PHP 8.0.24, or PHP 8.1.11+.
  1. I had some compilation errors with version 22 and I didn't investigate further but here are some answers:
  • Version 22.0.0 introduces features requiring PHP 8.1+ (PSR, GRPC)
  • c-ares and brotli support only in 22.0.0+
  • 22.x/25.x Branch: Active development, new features
  • 4.x Branch: Bug fixes and security only (legacy)
  • PHP 8.0 remains on the 4.x branch as it is nearing its end of life

@BjarneDMat
Copy link
Contributor

you seem to have much more insight into openswoole than I have 👍 I'm - more or less - just a glorified clerk attempting to keep everything current. 🤔
So, in in your opinion it's best to keep every version of php < 8.1 on the 4.11.x branch ?

@ArtKoKo
Copy link
Author

ArtKoKo commented Nov 24, 2025

Okay, your question is relevant, so I investigated OpenSwoole's backward compatibility:

Given that OpenSwoole itself dropped support for PHP 7 in its 4 branch, and that there are no compatible versions available: OpenSwoole never had versions for older PHP 5/7, and that OpenSwoole is a recent fork of Swoole (2021), therefore it has no legacy history.

If I refer to the OpenSwoole articles:

https://openswoole.com/article/v4-12-0-released
https://openswoole.com/article/openswoole-v4-8-0-released

Since MacPorts' philosophy is to support older versions of macOS and PHP, with appropriate and functional extension versions, but not necessarily the latest ones everywhere.

I would recommend this breakdown:

php.branches 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4

if {[vercmp ${php.branch} >= 8.4]} {
version 25.2.0
# Support PHP 8.4
} elseif {[vercmp ${php.branch} >= 8.2]} {
version 25.2.0
# Support PHP 8.2+
} elseif {[vercmp ${php.branch} >= 8.1]} {
version 22.1.2
# last version 22.x stable
} elseif {[vercmp ${php.branch} >= 8.0]} {
version 4.12.1
# last version 4.x with support PHP 8.0
} else {
# PHP 7.2 7.3 7.4
version 4.10.0
}

PortFile.txt

BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Nov 24, 2025
@BjarneDMat
Copy link
Contributor

I found your patch in the openswoole bug report and tried to apply it.
BUT it fails. It seems as if you aren't referencing the correct version of openswoole.
In openswoole-25.2.0 the lines you references don't match:

--- a/ext-src/php_swoole.cc
@@ 45,6@@

static swoole::CallbackManager rshutdown_callbacks;

SW_EXTERN_C_BEGIN
static PHP_FUNCTION(swoole_internal_call_user_shutdown_begin);
SW_EXTERN_C_END
@@ 154,6@@
static void php_swoole_init_globals(zend_openswoole_globals *openswoole_globals) {
    openswoole_globals->enable_coroutine = 1;
    openswoole_globals->enable_preemptive_scheduler = 0;
    openswoole_globals->socket_buffer_size = SW_SOCKET_BUFFER_SIZE;
    openswoole_globals->display_errors = 1;
}
@@ 166,6@@
        &function_name, 0, &shutdown_function_entry.fci, &shutdown_function_entry.fci_cache, NULL, NULL);
    register_user_shutdown_function(Z_STRVAL(function_name), Z_STRLEN(function_name), &shutdown_function_entry);
}

void php_swoole_set_global_option(HashTable *vht) {
    zval *ztmp;

@ArtKoKo
Copy link
Author

ArtKoKo commented Nov 24, 2025

Oops, I got a bit cheeky suggesting a hastily written patch based on an old OpenSwoole source code. Here's a patch that actually works: I tested and compiled it with my PHP 8.5 version and it seems to work, tell me.

In the PortFile:

if {[vercmp ${php.branch} >= 8.2]} {
    version             25.2.0
    revision            0
    checksums           rmd160  745e2859737fb01da2adb32ca032c2fd63a4e3ed \
                        sha256  bcc1fed4877b6646cb8f79b092ba03d5e495800465a3fff83c065c58d4312d40 \
                        size    1239054

    # PHP 8.5 compatibility patch
    if {[vercmp ${php.branch} >= 8.5]} {
        patchfiles-append   php85-openswoole.patch
    }
}

php85-openswoole.patch

@BjarneDMat
Copy link
Contributor

The @@ part is incorrect. Should be:
@@ -161,12 +161,27 @@ static void php_swoole_init_globals(zen

curl -L 'https://github.com/user-attachments/files/23725615/php85-openswoole.patch' \
| sed -E -e '1,/^@@/d' -e '/^\+/d' \
| wc -l
12
curl -L 'https://github.com/user-attachments/files/23725615/php85-openswoole.patch' \
| sed -E -e '1,/^@@/d' \
| wc -l
27
#=> port -q installed | awk '/php..-openswoole/'
  php74-openswoole @4.10.0_2 (active)
  php80-openswoole @4.12.1_0 (active)
  php81-openswoole @22.1.2_0 (active)
  php82-openswoole @25.2.0_1 (active)
  php83-openswoole @25.2.0_1 (active)
  php84-openswoole @25.2.0_1 (active)
  php85-openswoole @25.2.0_1 (active)

BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Nov 24, 2025
@ArtKoKo
Copy link
Author

ArtKoKo commented Nov 24, 2025

I've lost count on my fingers...
Thanks for your effort in updating MacPorts !

For your last commit :
Shouldn't the patch only be applied from PHP version 8.5 onwards?

@BjarneDMat
Copy link
Contributor

For your last commit : Shouldn't the patch only be applied from PHP version 8.5 onwards?

The +#if PHP_VERSION_ID >= 80500 takes care of that

@ArtKoKo
Copy link
Author

ArtKoKo commented Nov 24, 2025

Okay, you apply the patch permanently and rely on the patch's condition, that works for me

@ArtKoKo ArtKoKo closed this Nov 30, 2025
BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Nov 30, 2025
BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Dec 1, 2025
@BjarneDMat
Copy link
Contributor

BjarneDMat commented Dec 6, 2025

We might need to re-open and take a fresh look at the patch-php85-php_shutdown_function_entry.diff
When I activate the php85-openswoole extension php85 segfaults: Segmentation fault: 11

@ArtKoKo ArtKoKo reopened this Dec 7, 2025
This commit addresses two critical issues preventing php-openswoole
from building and running on macOS with PHP 8.5:

1. PHP 8.5 API Incompatibility (Segmentation Fault)
   - Problem: PHP 8.5 removed the 'fci' field from php_shutdown_function_entry
   - Symptom: Segfault (exit 139) when loading openswoole extension
   - Root Cause: php_swoole_register_shutdown_function() attempted to access
     the removed 'fci' field in shutdown_function_entry structure
   - Solution: Created php85-compat.patch that uses a temporary zend_fcall_info
     structure to initialize fci_cache, then only passes fci_cache to
     register_user_shutdown_function()

2. macOS Build Failures (Linux-specific Functions)
   - Problem: OpenSwoole uses 10 Linux-specific functions unavailable on macOS
   - Functions disabled via post-patch reinplace commands:
     * pthread_spin_lock / pthread_spinlock_t (no spinlock types in macOS)
     * pthread_barrier_init / pthread_barrier_t (no barrier types in macOS)
     * pthread_mutex_timedlock (not available on macOS)
     * pthread_mutexattr_setrobust / pthread_mutex_consistent (no robust mutexes)
     * getrandom (use arc4random fallback on macOS)
     * accept4 (Linux-specific socket function)
     * signalfd (Linux-specific signal handling)
     * malloc_trim (GNU-specific memory optimization)
     * epoll_create (Linux-specific I/O event notification, use kqueue on macOS)
   - Solution: Disable detection of these functions in config.m4 via reinplace

Changes:
- Portfile: Incremented revision to 11
- Portfile: Added post-patch block with 10 reinplace commands to disable
  Linux-specific function detection
- Portfile: Added conditional patch application for PHP 8.5+
- Added files/php85-compat.patch: Fix shutdown function registration for PHP 8.5

Testing:
- Compilation successful on macOS 15.7.2 (arm64) with PHP 8.5.0
- Extension loads without segfault: php85 -d extension=openswoole.so -m
- Basic functionality verified: OPENSWOOLE_VERSION constant accessible
- HTTP Server creation works: new Swoole\HTTP\Server() succeeds

Closes: macports#30146
…ity fixes

This commit updates php-swoole and adds comprehensive support for PHP 8.5
and macOS build compatibility.

Changes to php-swoole:

1. Version Update
   - Updated from 6.1.2 to 6.1.4
   - Updated checksums for new version
   - Added PHP 8.5 to supported branches

2. macOS Build Compatibility (all PHP versions >= 8.1)
   - Added post-patch block to disable Linux-specific pthread functions
   - Disabled 10 Linux-only functions not available on macOS:
     * pthread_spin_lock (no spinlock types in macOS pthread)
     * pthread_barrier_init (no barrier types in macOS pthread)
     * pthread_mutex_timedlock (not available on macOS)
     * pthread_mutexattr_setrobust (no robust mutex support)
     * pthread_mutex_consistent (no robust mutex support)
     * getrandom (use arc4random fallback on macOS)
     * accept4 (Linux-specific socket function)
     * signalfd (Linux-specific signal handling)
     * malloc_trim (GNU-specific memory optimization)
     * epoll_create (Linux I/O notification, use kqueue on macOS)

3. PHP 8.5 Compatibility Patches
   - Added php85-runtime.patch: Fix runtime API changes
   - Added php85-sapi.patch: Fix SAPI layer compatibility
   - Added php85-shutdown.patch: Fix shutdown function registration
   - Patches applied conditionally for PHP 8.5+

Changes to php-openswoole:
   - Minor formatting cleanup in Portfile header

Testing:
   - Built successfully on macOS 15.7.2 (arm64)
   - Tested with PHP 8.1, 8.2, 8.3, 8.4, and 8.5
   - Extension loads without errors
   - Basic HTTP server functionality verified
@ArtKoKo
Copy link
Author

ArtKoKo commented Dec 7, 2025

You're right, I tried using the ports but it didn't work. The OpenSwoole and Swoole versions for PHP 85 require a lot of patches to work; I've committed both. I'd appreciate it if a MacPorts maintainer could review the two ports, as I'm not an expert…

BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Dec 7, 2025
BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Dec 7, 2025
@BjarneDMat
Copy link
Contributor

BjarneDMat commented Dec 7, 2025

#!/usr/bin/env bash

usage () {
cat << TXT
Usage :
    ${0##*/} <action> [phpVersion ...]
        action : (activate|check|deactivate)
        phpVersion : php[:digit:]{2,} ; default : php74 php80 php81 php82 php83 php84 php85
TXT
}

prefix='/opt/local'

action="${1}" ; shift
phpVers=( php74 php80 php81 php82 php83 php84 php85 )
[[ -n "${1}" ]] && phpVers=( "$@" )

for php in "${phpVers[@]}"
do
    case "${action}" in
        ('activate')
            port deactivate ${php}-swoole 2>/dev/null
            port activate ${php}-sockets ${php}-openswoole
            cd "${prefix}/var/db/${php}"
            sed -i '' -E -e 's!^extension!;extension!' sockets.ini
            sed -i '' -E -e '/^extension/d'   openswoole.ini
            echo 'extension=sockets.so'    >> openswoole.ini
            echo 'extension=openswoole.so' >> openswoole.ini
        ;&
        ('check')
            ( exec ${php} -v )
            if [[ ${php} < php81 ]]
            then
                ( exec ${php} -r 'echo "OpenSwoole Version : " . SWOOLE_VERSION . PHP_EOL ;' )
            else
                ( exec ${php} -r 'echo "OpenSwoole Version : " . OPENSWOOLE_VERSION . PHP_EOL ;' )
            fi
            ( exec ${php} -m )
        ;;
        ('deactivate')
            port -f deactivate ${php}-sockets ${php}-openswoole
            port activate ${php}-sockets
        ;;
        (*)
            usage
            exit 1
        ;;
    esac
done

@BjarneDMat
Copy link
Contributor

I've tested the very, very basic functionalty of both php-openswoole and php-swoole in
phpVers=( php74 php80 php81 php82 php83 php84 php85 )
on both

Model Identifier: Macmini6,1                Model Identifier: MacPro5,1
macOS 10.15.7 19H2026 x86_64                macOS 15.7.1 24G231 x86_64
Xcode 12.4 12D4e                            Xcode 26.0.1 17A400
Command Line Tools 12.4.0.0.1.1610135815    Command Line Tools 26.0.0.0.1.1757719676

@ArtKoKo If you've got a php script that tests more extensively, I'll be happy to implement that 🤓

@ArtKoKo
Copy link
Author

ArtKoKo commented Dec 8, 2025

I adapted one of my previous scripts to check Apache, execute:

sudo ./test-open_swoole.sh test-all php85

test-open_swoole.sh

Example result:

Activating Swoole...
---> Deactivating php85-openswoole @25.2.0_11
---> Cleaning php85-openswoole
---> Computing dependencies for php85-sockets
---> Cleaning php85-sockets
---> Computing dependencies for php85-swoole
---> Activating php85-swoole @6.1.4_0
---> Cleaning php85-swoole

=========================================
Testing php85 with swoole 6.1.4
=========================================

--- PHP Version (swoole) ---
PHP 8.5.0 (cli) (built: Nov 22 2025 16:31:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.0, Copyright (c) Zend Technologies
with Zend OPcache v8.5.0, Copyright (c), by Zend Technologies

--- Extension Detection ---
✓ Extension loaded: swoole

--- Version Constant Check ---
✓ Swoole Version: 6.1.4

--- HTTP Server Creation Test ---
✓ HTTP server successfully created (Swoole\HTTP\Server on port 23415)

--- Loaded Modules ---
✓ sockets
✓ swoole

Activating OpenSwoole...
---> Deactivating php85-swoole @6.1.4_0
---> Cleaning php85-swoole
---> Computing dependencies for php85-sockets
---> Cleaning php85-sockets
---> Computing dependencies for php85-openswoole
---> Activating php85-openswoole @25.2.0_11
---> Cleaning php85-openswoole
---> Some of the ports you installed have notes:
php85-openswoole has the following notes:
You'll have to make sure the php85-sockets extension loads before the php85-openswoole extension.
You can do this by either:
1) adding priority statements to both the /opt/local/var/db/php85/sockets.ini file
and the /opt/local/var/db/php85/openswoole.ini file
2) add 'extension=sockets.so' to the /opt/local/var/db/php85/sockets.ini file
and disable it in the /opt/local/var/db/php85/sockets.ini file
see : swoole/swoole-src#3952

=========================================
Testing php85 with openswoole 25.2.0
=========================================

--- PHP Version (openswoole) ---
PHP 8.5.0 (cli) (built: Nov 22 2025 16:31:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.0, Copyright (c) Zend Technologies
with Zend OPcache v8.5.0, Copyright (c), by Zend Technologies

--- Extension Detection ---
✓ Extension loaded: openswoole

--- Version Constant Check ---
✓ OpenSwoole Version: 25.2.0

--- HTTP Server Creation Test ---
✓ HTTP server successfully created (OpenSwoole\HTTP\Server on port 29573)

--- Loaded Modules ---
✓ openswoole
✓ sockets

=========================================
Tests completed
=========================================

Restoring older versions 7.2 and 7.3 that were accidentally deleted
BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Dec 9, 2025
BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Dec 9, 2025
BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Dec 9, 2025
BjarneDMat pushed a commit to BjarneDMat/macports-ports that referenced this pull request Dec 9, 2025
@BjarneDMat
Copy link
Contributor

# This extension must load after the sockets extension
php.extension_ini       ~${php.extension_ini}

This doesn't work on macOs . macOs sorts ASCII 123..126 as being !before! 'a' 🤔👎🏻🤓

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

Development

Successfully merging this pull request may close these issues.

4 participants