Skip to content

Commit 8a5d3cf

Browse files
committed
Initialize the server when a remote object call occurs
1 parent aa3ab25 commit 8a5d3cf

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

ext-src/php_swoole_library.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
+----------------------------------------------------------------------+
1515
*/
1616

17-
/* $Id: 9e494000a6495581a5d59439cf15504c2bbdeaad */
17+
/* $Id: 54ad6d15fb4330384673e6d6a8317c46d0ca78a3 */
1818

1919
#ifndef SWOOLE_LIBRARY_H
2020
#define SWOOLE_LIBRARY_H
@@ -11003,6 +11003,10 @@ static const char* swoole_library_source_functions =
1100311003
" * @var array<string, mixed>\n"
1100411004
" */\n"
1100511005
" public static array $options = [];\n"
11006+
"\n"
11007+
" public static bool $remote_object_server_initiated = false;\n"
11008+
"\n"
11009+
" public static string $remote_object_server_socket_file = '';\n"
1100611010
"}\n"
1100711011
"\n"
1100811012
"/**\n"
@@ -11240,13 +11244,19 @@ static const char* swoole_library_source_functions =
1124011244
"\n"
1124111245
"function swoole_get_default_remote_object_client(): Swoole\\RemoteObject\\Client\n"
1124211246
"{\n"
11243-
" $dir = swoole_library_get_option('default_remote_object_server_dir');\n"
11244-
" if (empty($dir)) {\n"
11245-
" $home = getenv('HOME') ?: sys_get_temp_dir();\n"
11246-
" $dir = $home . '/.swoole';\n"
11247+
" if (!SwooleLibrary::$remote_object_server_initiated) {\n"
11248+
" SwooleLibrary::$remote_object_server_initiated = true;\n"
11249+
" swoole_init_default_remote_object_server();\n"
11250+
" }\n"
11251+
" if (!SwooleLibrary::$remote_object_server_socket_file) {\n"
11252+
" $dir = swoole_library_get_option('default_remote_object_server_dir');\n"
11253+
" if (empty($dir)) {\n"
11254+
" $home = getenv('HOME') ?: sys_get_temp_dir();\n"
11255+
" $dir = $home . '/.swoole';\n"
11256+
" }\n"
11257+
" SwooleLibrary::$remote_object_server_socket_file = 'unix://' . $dir . '/remote-object-server.sock';\n"
1124711258
" }\n"
11248-
" $socket_file = 'unix://' . $dir . '/remote-object-server.sock';\n"
11249-
" return new Swoole\\RemoteObject\\Client($socket_file);\n"
11259+
" return new Swoole\\RemoteObject\\Client(SwooleLibrary::$remote_object_server_socket_file);\n"
1125011260
"}\n";
1125111261

1125211262
static const char* swoole_library_source_alias =

ext-src/swoole_runtime.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,10 +1790,6 @@ bool PHPCoroutine::enable_hook(uint32_t flags) {
17901790
sw_unset_bit(flags, HOOK_MONGODB);
17911791
}
17921792

1793-
if ((flags & HOOK_MONGODB) || (flags & HOOK_NET_FUNCTION)) {
1794-
zend::function::call(R"(swoole_init_default_remote_object_server)", 0, nullptr);
1795-
}
1796-
17971793
hook_stream_factory(&flags);
17981794
hook_stream_ops(flags);
17991795
hook_pdo_driver(flags);

0 commit comments

Comments
 (0)