Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 86 additions & 20 deletions php/php-openswoole/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,57 @@
PortSystem 1.0
PortGroup php 1.1

epoch 1
name php-openswoole
categories-append net devel
maintainers {ryandesign @ryandesign} openmaintainer
license Apache-2

php.branches 7.2 7.3 7.4 8.0 8.1 8.2
php.branches 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4 8.5
php.pecl yes

if {[vercmp ${php.branch} >= 7.4]} {
version 22.0.0
revision 1
checksums rmd160 9c9c2da1afd86be905ccc9b692450cf0af4f43c0 \
sha256 bf1ebf241bd4a52b5b39102a37da8cfa4b3dfcbd2be4104adf408873dac89034 \
size 1244040
} elseif {[vercmp ${php.branch} >= 7.2]} {
# This extension must load after the sockets extension
php.extension_ini ~${php.extension_ini}

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

# macOS pthread compatibility (all PHP versions)
# Disable Linux-specific features not available on macOS
post-patch {
reinplace "s|AC_CHECK_LIB(pthread, pthread_spin_lock|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_spin_lock|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(pthread, pthread_barrier_init|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_barrier_init|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(pthread, pthread_mutex_timedlock|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_mutex_timedlock|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(pthread, pthread_mutexattr_setrobust|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_mutexattr_setrobust|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(pthread, pthread_mutex_consistent|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_mutex_consistent|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, getrandom|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, getrandom|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, accept4|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, accept4|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, signalfd|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, signalfd|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, malloc_trim|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, malloc_trim|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, epoll_create|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, epoll_create|g" ${worksrcpath}/config.m4
}

# PHP 8.5+ compatibility patch
if {[vercmp ${php.branch} >= 8.5]} {
patchfiles-append php85-compat.patch
}
} elseif {[vercmp ${php.branch} >= 8.1]} {
version 22.1.2
revision 0
checksums rmd160 554eb7fa11c1927e57f7bdb5ca4eb820fbf9f548 \
sha256 ec9d08e9484bf95a0080738342a84f09b9c5b8222f4a03c4736caacb7668cb46 \
size 1252932
} elseif {[vercmp ${php.branch} >= 8.0]} {
version 4.12.1
revision 0
checksums rmd160 dc66de146301258d9364b42ea486a1d1bf0523f2 \
sha256 64559632340aa67b09d6386b204750b7b58fb791e4e6ea8e8b610952935260b5 \
size 1637580
} else {
version 4.10.0
revision 2
checksums rmd160 074542644edb0ff9815a7179d4d3ad0172c0d1cd \
Expand All @@ -26,34 +62,64 @@ if {[vercmp ${php.branch} >= 7.4]} {
patchfiles arm.patch
}

description an event-driven asynchronous & concurrent & coroutine networking engine with high performance for PHP
description High Performance Programmatic Server for PHP with Async IO, Coroutines and Fibers

long_description OpenSwoole is a high-performance network framework for PHP. \
It enables PHP developers to write high-performance, scalable, \
concurrent TCP, UDP, Unix Socket, HTTP, and WebSocket services \
without requiring in-depth knowledge about non-blocking I/O \
programming and low-level Linux kernel. OpenSwoole is a fork \
of Swoole with additional features and improvements.

long_description ${name} is ${description}.
notes "
You'll have to make sure the ${php}-sockets extension loads before the ${php}-openswoole extension.
You can do this by either:
1) adding priority statements to both the ${prefix}/var/db/${php}/sockets.ini file
and the ${prefix}/var/db/${php}/openswoole.ini file
2) add 'extension=sockets.so' to the ${prefix}/var/db/${php}/sockets.ini file
and disable it in the ${prefix}/var/db/${php}/sockets.ini file
see : https://github.com/swoole/swoole-src/issues/3952
"

if {${name} ne ${subport}} {
conflicts ${php}-swoole

PortGroup legacysupport 1.1
# strndup
legacysupport.newest_darwin_requires_legacy \
10
# https://github.com/swoole/swoole-src/issues/3896
# CLOCK_REALTIME
legacysupport.newest_darwin_requires_legacy \
15

conflicts ${php}-swoole

compiler.cxx_standard 2011
compiler.thread_local_storage yes

depends_lib-append port:brotli \
depends_lib-append port:${php}-sockets \
port:hiredis \
port:nghttp2 \
path:lib/libssl.dylib:openssl \
port:zlib

configure.args --enable-async-redis \
--enable-http2 \
compiler.blacklist-append \
*gcc-4.0 *gcc-4.2

configure.args --enable-http2 \
--enable-openssl \
--enable-swoole \
--enable-sockets \
--enable-mysqlnd \
--with-openssl-dir=${prefix}

# brotli and c-ares support only in versions >= 22.0.0
if {[vercmp ${version} >= 22.0.0]} {
depends_lib-append \
port:brotli \
port:c-ares

configure.args-append \
--enable-cares
}

# macOS requires undefined dynamic_lookup for cross-extension symbols
configure.ldflags-append \
-undefined dynamic_lookup

use_parallel_build yes
}
28 changes: 28 additions & 0 deletions php/php-openswoole/files/php85-compat.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--- ext-src/php_swoole.cc.orig
+++ ext-src/php_swoole.cc
@@ -162,9 +162,25 @@
php_shutdown_function_entry shutdown_function_entry;
zval function_name;
ZVAL_STRING(&function_name, function);
+#if PHP_VERSION_ID >= 80500
+ // PHP 8.5: shutdown function structure changed - removed fci field
+ // Create temporary fci to initialize fci_cache, then only use fci_cache
+ zend_fcall_info fci_tmp;
+ shutdown_function_entry.params = NULL;
+ shutdown_function_entry.param_count = 0;
+
+ if (zend_fcall_info_init(&function_name, 0, &fci_tmp,
+ &shutdown_function_entry.fci_cache, NULL, NULL) != SUCCESS) {
+ zval_ptr_dtor(&function_name);
+ return;
+ }
+
+ register_user_shutdown_function(Z_STRVAL(function_name), Z_STRLEN(function_name), &shutdown_function_entry);
+#else
zend_fcall_info_init(
&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);
+#endif
}

void php_swoole_set_global_option(HashTable *vht) {
32 changes: 30 additions & 2 deletions php/php-swoole/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,38 @@ categories-append net devel
maintainers {ryandesign @ryandesign} openmaintainer
license Apache-2

php.branches 5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2
php.branches 5.3 5.4 5.5 5.6 7.0 7.1 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4 8.5
php.pecl yes

if {[vercmp ${php.branch} >= 8.0]} {
if {[vercmp ${php.branch} >= 8.1]} {
version 6.1.4
revision 0
checksums rmd160 dc763a78fcc8788c6273fa148b869e6f3f7ceae2 \
sha256 b0edefe2985360099a5701045258e003dc98868a8d966821ce81af2c7569770a \
size 2455442

# macOS pthread compatibility (all PHP versions)
# Disable Linux-specific features not available on macOS
post-patch {
reinplace "s|AC_CHECK_LIB(pthread, pthread_spin_lock|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_spin_lock|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(pthread, pthread_barrier_init|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_barrier_init|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(pthread, pthread_mutex_timedlock|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_mutex_timedlock|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(pthread, pthread_mutexattr_setrobust|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_mutexattr_setrobust|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(pthread, pthread_mutex_consistent|dnl DISABLED_ON_MACOS AC_CHECK_LIB(pthread, pthread_mutex_consistent|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, getrandom|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, getrandom|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, accept4|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, accept4|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, signalfd|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, signalfd|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, malloc_trim|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, malloc_trim|g" ${worksrcpath}/config.m4
reinplace "s|AC_CHECK_LIB(c, epoll_create|dnl DISABLED_ON_MACOS AC_CHECK_LIB(c, epoll_create|g" ${worksrcpath}/config.m4
}

# PHP 8.5+ compatibility patches
if {[vercmp ${php.branch} >= 8.5]} {
patchfiles-append php85-runtime.patch \
php85-sapi.patch \
php85-shutdown.patch
}
} elseif {[vercmp ${php.branch} >= 8.0]} {
version 5.0.3
revision 1
checksums rmd160 c8d3b6e892b2c2bc919ac0da36c6837b4315bfa6 \
Expand Down
18 changes: 18 additions & 0 deletions php/php-swoole/files/php85-runtime.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- ext-src/swoole_runtime.cc.orig
+++ ext-src/swoole_runtime.cc
@@ -190,12 +190,10 @@
memcpy(new_list, old_list, ZEND_TYPE_LIST_SIZE(old_list->num_types));
ZEND_TYPE_SET_PTR(new_arg_info[i].type, new_list);

- zend_type *list_type;
- ZEND_TYPE_LIST_FOREACH(new_list, list_type) {
- zend_string *name = zend_string_dup(ZEND_TYPE_NAME(*list_type), true);
- ZEND_TYPE_SET_PTR(*list_type, name);
+ for (uint32_t j = 0; j < new_list->num_types; j++) {
+ zend_string *name = zend_string_dup(ZEND_TYPE_NAME(new_list->types[j]), true);
+ ZEND_TYPE_SET_PTR(new_list->types[j], name);
}
- ZEND_TYPE_LIST_FOREACH_END();
} else if (ZEND_TYPE_HAS_NAME(arg_info[i].type)) {
zend_string *name = zend_string_dup(ZEND_TYPE_NAME(arg_info[i].type), true);
ZEND_TYPE_SET_PTR(new_arg_info[i].type, name);
14 changes: 14 additions & 0 deletions php/php-swoole/files/php85-sapi.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- thirdparty/php/main/SAPI.h.orig
+++ thirdparty/php/main/SAPI.h
@@ -38,7 +38,11 @@

switch (arg) {
case PARSE_STRING:
+#if PHP_VERSION_ID >= 80500
+ separator = ZSTR_VAL(PG(arg_separator).input);
+#else
separator = PG(arg_separator).input;
+#endif
break;
case PARSE_COOKIE:
separator = (char *) ";\0";
23 changes: 23 additions & 0 deletions php/php-swoole/files/php85-shutdown.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- ext-src/php_swoole.cc.orig
+++ ext-src/php_swoole.cc
@@ -274,11 +274,20 @@
void php_swoole_register_shutdown_function(const char *function) {
php_shutdown_function_entry shutdown_function_entry;
#if PHP_VERSION_ID >= 80500
+ // PHP 8.5: Initialize fci_cache via zend_fcall_info_init
zval function_name;
+ zend_fcall_info fci_tmp;
memset(&shutdown_function_entry, 0, sizeof(php_shutdown_function_entry));
ZVAL_STRING(&function_name, function);
shutdown_function_entry.params = NULL;
shutdown_function_entry.param_count = 0;
+
+ if (zend_fcall_info_init(&function_name, 0, &fci_tmp,
+ &shutdown_function_entry.fci_cache, nullptr, nullptr) != SUCCESS) {
+ zval_ptr_dtor(&function_name);
+ return;
+ }
+
register_user_shutdown_function(Z_STRVAL(function_name), Z_STRLEN(function_name), &shutdown_function_entry);
zval_ptr_dtor(&function_name);
#else