Search code examples
phpdockershared-librariesopenswoole

how to fix swoole_version not found with docker.io/openswoole/swoole:php7.4-alpine, even with openswoole.so loaded


I'm trying to text openswoole http server using docker image docker.io/openswoole/swoole:php7.4-alpine , but, I can't even find the function swoole_version(), I already check the php --ri openswoole, the libs is there. This is the output

openswoole

openswoole

Open Swoole => enabled
Author => Open Swoole Group <[email protected]>
Version => 22.0.0
Built => Mar 13 2023 02:04:41
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1t  7 Feb 2023
dtls => enabled
http2 => enabled
hook-curl => enabled
pcre => enabled
zlib => 1.2.12
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
postgresql => enabled

Directive => Local Value => Master Value
openswoole.enable_coroutine => On => On
openswoole.enable_preemptive_scheduler => Off => Off
openswoole.display_errors => On => On
openswoole.unixsock_buffer_size => 8388608 => 8388608

I tried to search google/search engine, and git repo, seems they only pointed to not loaded lib or .so file, but in my case it's there. The 2nd try is to check the registered function seems only some of openswoole function is there.

I tried check using this code

<?php 

$function = get_defined_functions()["internal"];

$result = array_filter($function, function($d) { return strpos($d, "swoole") !== false; });

var_dump($result);

The output is

array(23) {
  [1227]=>
  string(23) "swoole_coroutine_create"
  [1228]=>
  string(22) "swoole_coroutine_defer"
  [1229]=>
  string(27) "swoole_coroutine_socketpair"
  [1230]=>
  string(28) "swoole_test_kernel_coroutine"
  [1231]=>
  string(40) "swoole_internal_call_user_shutdown_begin"
  [1234]=>
  string(16) "swoole_event_add"
  [1235]=>
  string(16) "swoole_event_del"
  [1236]=>
  string(16) "swoole_event_set"
  [1237]=>
  string(18) "swoole_event_isset"
  [1238]=>
  string(21) "swoole_event_dispatch"
  [1239]=>
  string(18) "swoole_event_defer"
  [1240]=>
  string(18) "swoole_event_cycle"
  [1241]=>
  string(18) "swoole_event_write"
  [1242]=>
  string(17) "swoole_event_wait"
  [1243]=>
  string(17) "swoole_event_exit"
  [1244]=>
  string(18) "swoole_timer_after"
  [1245]=>
  string(17) "swoole_timer_tick"
  [1246]=>
  string(19) "swoole_timer_exists"
  [1247]=>
  string(17) "swoole_timer_info"
  [1248]=>
  string(18) "swoole_timer_stats"
  [1249]=>
  string(17) "swoole_timer_list"
  [1250]=>
  string(18) "swoole_timer_clear"
  [1251]=>
  string(22) "swoole_timer_clear_all"
}

Based on PHP.net docs (https://www.php.net/manual/en/ref.swoole-funcs.php), there should be a function called swoole_version, but seems the official docker image and the openswoole.so doesn't have it.

Is it by design? Or I need to pay something to use it? Or there are some conf that I need to enable?

Any pointer is really appreciated. Thanks


Solution

  • swoole and openswoole are not the same. The php docs are reffering to the swoole plugin and openswoole is a fork with a different documentation: https://openswoole.com/docs

    You can use the following constants in openswoole: https://github.com/openswoole/ide-helper/blob/master/src/OpenSwoole/Constant.php#L11

    \OpenSwoole\Constant::VERSION
    

    Or you can use this function:

    https://github.com/openswoole/ide-helper/blob/4fdabcbb5db48bc8bdc5262208f9d2fc976f4b79/src/OpenSwoole/Util.php#LL13C11-L13C11

    \OpenSwoole\Util::getVersion()