Skip to content

Commit

Permalink
Optimize thread server
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed May 29, 2024
1 parent 1491939 commit 6c33623
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions examples/thread/thread_server.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
$http = new Swoole\Http\Server("0.0.0.0", 9503);
$http = new Swoole\Http\Server("0.0.0.0", 9503, SWOOLE_THREAD);
$http->set([
'worker_num' => 2,
'task_worker_num' => 3,
Expand Down Expand Up @@ -31,10 +31,10 @@
echo "[worker#" . $http->getWorkerId() . "]\treceived pipe message[$msg] from " . $srcWorkerId . "\n";
});

//$http->addProcess(new \Swoole\Process(function () {
// echo "user process, id=" . \Swoole\Thread::getId();
// sleep(2000);
//}));
$http->addProcess(new \Swoole\Process(function () {
echo "user process, id=" . \Swoole\Thread::getId() . "\n";
sleep(2);
}));

$http->on('Task', function ($server, $taskId, $srcWorkerId, $data) {
var_dump($taskId, $srcWorkerId, $data);
Expand Down
4 changes: 3 additions & 1 deletion ext-src/swoole_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,9 @@ void php_swoole_thread_start(zend_string *file, zend_string *argv_serialized) {

_startup_error:
zend_string_release(file);
zend_string_release(argv_serialized);
if (argv_serialized) {
zend_string_release(argv_serialized);
}
ts_free_thread();
swoole_thread_clean();
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/master.cc
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ int Server::start_master_thread(Reactor *reactor) {
}

#ifdef HAVE_PTHREAD_BARRIER
if (!single_thread) {
if (is_process_mode() && !single_thread) {
pthread_barrier_wait(&reactor_thread_barrier);
}
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
Expand Down

0 comments on commit 6c33623

Please sign in to comment.