Skip to content

Commit

Permalink
Merge branch '4.0' of github.com:walkor/workerman into 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Jul 4, 2024
2 parents 1cc6f50 + 9107912 commit 0526361
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
21 changes: 18 additions & 3 deletions Protocols/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class Request
*/
protected static $_enableCache = true;

/**
* Is safe.
*
* @var bool
*/
protected $_isSafe = true;

/**
* Request constructor.
Expand Down Expand Up @@ -208,8 +214,8 @@ public function protocolVersion()
public function host($without_port = false)
{
$host = $this->header('host');
if ($host && $without_port && $pos = \strpos($host, ':')) {
return \substr($host, 0, $pos);
if ($host && $without_port) {
return preg_replace('/:\d{1,5}$/', '', $host);
}
return $host;
}
Expand Down Expand Up @@ -656,14 +662,23 @@ public function __toString()
return $this->_buffer;
}

/**
* __wakeup.
* @return void
*/
public function __wakeup()
{
$this->_isSafe = false;
}

/**
* __destruct.
*
* @return void
*/
public function __destruct()
{
if (isset($this->_data['files'])) {
if (isset($this->_data['files']) && $this->_isSafe) {
\clearstatcache();
\array_walk_recursive($this->_data['files'], function($value, $key){
if ($key === 'tmp_name') {
Expand Down
19 changes: 19 additions & 0 deletions Protocols/Http/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ class Session
*/
protected $_sessionId = null;

/**
* Is safe.
*
* @var bool
*/
protected $_isSafe = true;

/**
* Session constructor.
*
Expand Down Expand Up @@ -402,13 +409,25 @@ public function gc()
static::$_handler->gc(static::$lifetime);
}

/**
* __wakeup.
* @return void
*/
public function __wakeup()
{
$this->_isSafe = false;
}

/**
* __destruct.
*
* @return void
*/
public function __destruct()
{
if (!$this->_isSafe) {
return;
}
$this->save();
if (\rand(1, static::$gcProbability[1]) <= static::$gcProbability[0]) {
$this->gc();
Expand Down
7 changes: 5 additions & 2 deletions Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Worker
*
* @var string
*/
const VERSION = '4.0.45';
const VERSION = '4.0.46';

/**
* Status starting.
Expand Down Expand Up @@ -1057,7 +1057,10 @@ protected static function formatStatusData($statistics_file)
}
$status_str = '';
$current_total_request = array();
$worker_info = \unserialize($info[0]);
$worker_info = [];
try {
$worker_info = unserialize($info[0], ['allowed_classes' => false]);
} catch (Throwable $exception) {}
\ksort($worker_info, SORT_NUMERIC);
unset($info[0]);
$data_waiting_sort = array();
Expand Down

0 comments on commit 0526361

Please sign in to comment.