Skip to content

Commit ca67a05

Browse files
authored
Support coroutine runtime hook for pdo_firebird (#5925)
1 parent e4a380e commit ca67a05

24 files changed

+3562
-46
lines changed

‎composer.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"license": "Apache-2.0",
55
"description": "Swoole is an event-driven, asynchronous, coroutine-based concurrency library with high performance for PHP.",
66
"require": {
7-
"php": ">=8.1 <8.5"
7+
"php": ">=8.1 <8.5",
8+
"ext-pdo": "*"
89
},
910
"php-ext": {
1011
"extension-name": "swoole",

‎config.m4‎

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ PHP_ARG_ENABLE([swoole-pgsql],
106106
[AS_HELP_STRING([--enable-swoole-pgsql],
107107
[Enable postgresql support])], [no], [no])
108108

109+
PHP_ARG_WITH([swoole-firebird],
110+
[whether to enable firebird build flags],
111+
[AS_HELP_STRING([[--with-swoole-firebird[=DIR]]],
112+
[PDO: Async Firebird support. DIR is the Firebird base install directory
113+
[/opt/firebird]])], [no], [no])
114+
109115
PHP_ARG_ENABLE([thread-context],
110116
[whether to enable thread context],
111117
[AS_HELP_STRING([--enable-thread-context],
@@ -950,6 +956,52 @@ EOF
950956
fi
951957
dnl sqlite stop
952958

959+
dnl firebird start
960+
961+
if test "$PHP_SWOOLE_FIREBIRD" != "no"; then
962+
if test "$PHP_PDO" = "no" && test "$ext_shared" = "no"; then
963+
AC_MSG_ERROR([PDO is not enabled! Add --enable-pdo to your configure line.])
964+
fi
965+
966+
AC_PATH_PROG([FB_CONFIG], [fb_config], [no])
967+
968+
if test -x "$FB_CONFIG" && test "$PHP_PDO_FIREBIRD" = "yes"; then
969+
AC_MSG_CHECKING([for libfbconfig])
970+
FB_CFLAGS=$($FB_CONFIG --cflags)
971+
FB_LIBDIR=$($FB_CONFIG --libs)
972+
FB_VERSION=$($FB_CONFIG --version)
973+
AC_MSG_RESULT([version $FB_VERSION])
974+
AS_VERSION_COMPARE([$FB_VERSION], [3.0],
975+
[AC_MSG_ERROR([Firebird required version is at least 3.0])])
976+
PHP_EVAL_LIBLINE([$FB_LIBDIR], [SWOOLE_SHARED_LIBADD])
977+
PHP_EVAL_INCLINE([$FB_CFLAGS])
978+
else
979+
AS_VAR_IF([PHP_PDO_FIREBIRD], [yes], [
980+
FIREBIRD_INCDIR=
981+
FIREBIRD_LIBDIR=
982+
FIREBIRD_LIBDIR_FLAG=
983+
], [
984+
FIREBIRD_INCDIR=$PHP_PDO_FIREBIRD/include
985+
FIREBIRD_LIBDIR=$PHP_PDO_FIREBIRD/$PHP_LIBDIR
986+
FIREBIRD_LIBDIR_FLAG=-L$FIREBIRD_LIBDIR
987+
])
988+
989+
PHP_CHECK_LIBRARY([fbclient], [fb_get_master_interface],
990+
[],
991+
[AC_MSG_FAILURE([libfbclient not found.])],
992+
[$FIREBIRD_LIBDIR_FLAG])
993+
PHP_ADD_LIBRARY_WITH_PATH([fbclient],
994+
[$FIREBIRD_LIBDIR],
995+
[SWOOLE_SHARED_LIBADD])
996+
PHP_ADD_INCLUDE([$FIREBIRD_INCDIR])
997+
fi
998+
999+
PHP_CHECK_PDO_INCLUDES
1000+
AC_DEFINE(SW_USE_FIREBIRD, 1, [do we enable firebird coro support])
1001+
fi
1002+
1003+
dnl firebird stop
1004+
9531005
AC_CHECK_LIB(z, gzgets, [
9541006
AC_DEFINE(SW_HAVE_ZLIB, 1, [have zlib])
9551007
PHP_ADD_LIBRARY(z, 1, SWOOLE_SHARED_LIBADD)
@@ -1077,15 +1129,15 @@ EOF
10771129
PKG_CHECK_MODULES([URING], [liburing >= 2.0])
10781130

10791131
AC_SWOOLE_HAVE_IOURING_STATX
1080-
1132+
10811133
KERNEL_MAJOR=`uname -r | awk -F '.' '{print $1}'`
10821134
KERNEL_MINOR=`uname -r | awk -F '.' '{print $2}'`
10831135

10841136
if (test $KERNEL_MAJOR -eq 6 && test $KERNEL_MINOR -ge 9); then
10851137
dnl IORING_OP_FTRUNCATE is available since 6.9
10861138
AC_SWOOLE_HAVE_IOURING_FTRUNCATE
10871139
fi
1088-
1140+
10891141
if (test $KERNEL_MAJOR -eq 6 && test $KERNEL_MINOR -ge 7); then
10901142
dnl IORING_OP_FUTEX_WAKE/IORING_OP_FUTEX_WAIT is available since 6.7
10911143
AC_SWOOLE_HAVE_IOURING_FUTEX
@@ -1268,6 +1320,13 @@ EOF
12681320
fi
12691321
fi
12701322

1323+
if test "$PHP_SWOOLE_FIREBIRD" != "no"; then
1324+
swoole_source_file="$swoole_source_file \
1325+
thirdparty/php84/pdo_firebird/firebird_driver.c \
1326+
thirdparty/php84/pdo_firebird/firebird_statement.c \
1327+
thirdparty/php84/pdo_firebird/pdo_firebird_utils.cpp"
1328+
fi
1329+
12711330
SW_ASM_DIR="thirdparty/boost/asm/"
12721331
SW_USE_ASM_CONTEXT="yes"
12731332

@@ -1446,4 +1505,7 @@ EOF
14461505
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php83/pdo_sqlite)
14471506
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php84/pdo_sqlite)
14481507
fi
1508+
if test "$PHP_SWOOLE_FIREBIRD" != "no"; then
1509+
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/php84/pdo_firebird)
1510+
fi
14491511
fi

‎ext-src/php_swoole.cc‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,9 @@ PHP_MINIT_FUNCTION(swoole) {
902902
#ifdef SW_USE_SQLITE
903903
php_swoole_sqlite_minit(module_number);
904904
#endif
905+
#ifdef SW_USE_FIREBIRD
906+
php_swoole_firebird_minit(module_number);
907+
#endif
905908
#ifdef SW_THREAD
906909
php_swoole_thread_minit(module_number);
907910
php_swoole_thread_atomic_minit(module_number);
@@ -939,14 +942,15 @@ PHP_MSHUTDOWN_FUNCTION(swoole) {
939942
#ifdef SW_USE_PGSQL
940943
php_swoole_pgsql_mshutdown();
941944
#endif
942-
943945
#ifdef SW_USE_ORACLE
944946
php_swoole_oracle_mshutdown();
945947
#endif
946-
947948
#ifdef SW_USE_SQLITE
948949
php_swoole_sqlite_mshutdown();
949950
#endif
951+
#ifdef SW_USE_FIREBIRD
952+
php_swoole_firebird_mshutdown();
953+
#endif
950954

951955
swoole_clean();
952956

@@ -1079,6 +1083,9 @@ PHP_MINFO_FUNCTION(swoole) {
10791083
#ifdef SW_USE_SQLITE
10801084
php_info_print_table_row(2, "coroutine_sqlite", "enabled");
10811085
#endif
1086+
#ifdef SW_USE_FIREBIRD
1087+
php_info_print_table_row(2, "coroutine_firebird", "enabled");
1088+
#endif
10821089
#ifdef SW_USE_IOURING
10831090
php_info_print_table_row(2, "io_uring", "enabled");
10841091
#endif

‎ext-src/php_swoole_coroutine.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class PHPCoroutine {
137137
HOOK_PDO_ODBC = 1u << 17,
138138
HOOK_PDO_ORACLE = 1u << 18,
139139
HOOK_PDO_SQLITE = 1u << 19,
140+
HOOK_PDO_FIREBIRD = 1u << 20,
140141
#ifdef SW_USE_CURL
141142
HOOK_ALL = 0x7fffffff ^ HOOK_CURL,
142143
#else

‎ext-src/php_swoole_firebird.h‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Swoole |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 2012-2018 The Swoole Group |
6+
+----------------------------------------------------------------------+
7+
| This source file is subject to version 2.0 of the Apache license, |
8+
| that is bundled with this package in the file LICENSE, and is |
9+
| available through the world-wide-web at the following url: |
10+
| http://www.apache.org/licenses/LICENSE-2.0.html |
11+
| If you did not receive a copy of the Apache2.0 license and are unable|
12+
| to obtain it through the world-wide-web, please send a note to |
13+
| license@swoole.com so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: NathanFreeman <mariasocute@163.com> |
16+
+----------------------------------------------------------------------+
17+
*/
18+
#ifndef SWOOLE_SRC_PHP_SWOOLE_FIREBIRD_H
19+
#define SWOOLE_SRC_PHP_SWOOLE_FIREBIRD_H
20+
21+
#include "php_swoole.h"
22+
23+
#ifdef SW_USE_FIREBIRD
24+
25+
BEGIN_EXTERN_C()
26+
27+
#include "ext/pdo/php_pdo_driver.h"
28+
29+
#include "thirdparty/php84/pdo_firebird/php_pdo_firebird_int.h"
30+
31+
extern const pdo_driver_t swoole_pdo_firebird_driver;
32+
void swoole_firebird_set_blocking(bool blocking);
33+
34+
ISC_STATUS swoole_isc_attach_database(
35+
ISC_STATUS *, short, const ISC_SCHAR *, isc_db_handle *, short, const ISC_SCHAR *);
36+
ISC_STATUS swoole_isc_detach_database(ISC_STATUS *, isc_db_handle *);
37+
ISC_STATUS swoole_isc_dsql_execute(ISC_STATUS *, isc_tr_handle *, isc_stmt_handle *, unsigned short, const XSQLDA *);
38+
ISC_STATUS swoole_isc_dsql_execute2(
39+
ISC_STATUS *, isc_tr_handle *, isc_stmt_handle *, unsigned short, const XSQLDA *, const XSQLDA *);
40+
ISC_STATUS swoole_isc_dsql_sql_info(ISC_STATUS *, isc_stmt_handle *, short, const ISC_SCHAR *, short, ISC_SCHAR *);
41+
ISC_STATUS swoole_isc_dsql_free_statement(ISC_STATUS *, isc_stmt_handle *, unsigned short);
42+
ISC_STATUS swoole_isc_start_transaction(ISC_STATUS *, isc_tr_handle *, short, isc_db_handle *, size_t, char *);
43+
ISC_STATUS swoole_isc_commit_retaining(ISC_STATUS *, isc_tr_handle *);
44+
ISC_STATUS swoole_isc_commit_transaction(ISC_STATUS *, isc_tr_handle *);
45+
ISC_STATUS swoole_isc_rollback_transaction(ISC_STATUS *, isc_tr_handle *);
46+
ISC_STATUS swoole_isc_dsql_allocate_statement(ISC_STATUS *, isc_db_handle *, isc_stmt_handle *);
47+
ISC_STATUS swoole_isc_dsql_prepare(
48+
ISC_STATUS *, isc_tr_handle *, isc_stmt_handle *, unsigned short, const ISC_SCHAR *, unsigned short, XSQLDA *);
49+
ISC_STATUS swoole_isc_dsql_fetch(ISC_STATUS *, isc_stmt_handle *, unsigned short, const XSQLDA *);
50+
ISC_STATUS swoole_isc_open_blob(ISC_STATUS *, isc_db_handle *, isc_tr_handle *, isc_blob_handle *, ISC_QUAD *);
51+
ISC_STATUS swoole_isc_blob_info(ISC_STATUS *, isc_blob_handle *, short, const ISC_SCHAR *, short, ISC_SCHAR *);
52+
ISC_STATUS swoole_isc_get_segment(ISC_STATUS *, isc_blob_handle *, unsigned short *, unsigned short, ISC_SCHAR *);
53+
ISC_STATUS swoole_isc_put_segment(ISC_STATUS *, isc_blob_handle *, unsigned short, const ISC_SCHAR *);
54+
ISC_STATUS swoole_isc_close_blob(ISC_STATUS *, isc_blob_handle *);
55+
ISC_STATUS swoole_isc_create_blob(ISC_STATUS *, isc_db_handle *, isc_tr_handle *, isc_blob_handle *, ISC_QUAD *);
56+
ISC_STATUS swoole_isc_dsql_set_cursor_name(ISC_STATUS *, isc_stmt_handle *, const ISC_SCHAR *, unsigned short);
57+
ISC_STATUS swoole_fb_ping(ISC_STATUS *, isc_db_handle *);
58+
int swoole_isc_version(isc_db_handle *, ISC_VERSION_CALLBACK, void *);
59+
60+
#ifdef SW_USE_FIREBIRD_HOOK
61+
#define isc_attach_database swoole_isc_attach_database
62+
#define isc_detach_database swoole_isc_detach_database
63+
#define isc_dsql_execute swoole_isc_dsql_execute
64+
#define isc_dsql_execute2 swoole_isc_dsql_execute2
65+
#define isc_dsql_sql_info swoole_isc_dsql_sql_info
66+
#define isc_dsql_free_statement swoole_isc_dsql_free_statement
67+
#define isc_start_transaction swoole_isc_start_transaction
68+
#define isc_commit_retaining swoole_isc_commit_retaining
69+
#define isc_commit_transaction swoole_isc_commit_transaction
70+
#define isc_rollback_transaction swoole_isc_rollback_transaction
71+
#define isc_dsql_allocate_statement swoole_isc_dsql_allocate_statement
72+
#define isc_dsql_prepare swoole_isc_dsql_prepare
73+
#define isc_dsql_fetch swoole_isc_dsql_fetch
74+
#define isc_open_blob swoole_isc_open_blob
75+
#define isc_blob_info swoole_isc_blob_info
76+
#define isc_get_segment swoole_isc_get_segment
77+
#define isc_put_segment swoole_isc_put_segment
78+
#define isc_create_blob swoole_isc_create_blob
79+
#define isc_close_blob swoole_isc_close_blob
80+
#define isc_dsql_set_cursor_name swoole_isc_dsql_set_cursor_name
81+
#define fb_ping swoole_fb_ping
82+
#define isc_version swoole_isc_version
83+
#endif
84+
END_EXTERN_C()
85+
#endif
86+
#endif

‎ext-src/php_swoole_private.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ void php_swoole_oracle_minit(int module_number);
259259
#ifdef SW_USE_SQLITE
260260
void php_swoole_sqlite_minit(int module_number);
261261
#endif
262+
#ifdef SW_USE_FIREBIRD
263+
void php_swoole_firebird_minit(int module_number);
264+
#endif
262265
// server
263266
void php_swoole_server_minit(int module_number);
264267
void php_swoole_server_port_minit(int module_number);
@@ -341,6 +344,9 @@ void php_swoole_oracle_mshutdown();
341344
#ifdef SW_USE_SQLITE
342345
void php_swoole_sqlite_mshutdown();
343346
#endif
347+
#ifdef SW_USE_FIREBIRD
348+
void php_swoole_firebird_mshutdown();
349+
#endif
344350

345351
static sw_inline size_t php_swoole_get_send_data(zval *zdata, char **str) {
346352
convert_to_string(zdata);

0 commit comments

Comments
 (0)