Skip to content

Commit 0526361

Browse files
committed
Merge branch '4.0' of github.com:walkor/workerman into 4.0
2 parents 1cc6f50 + 9107912 commit 0526361

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

Protocols/Http/Request.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ class Request
7171
*/
7272
protected static $_enableCache = true;
7373

74+
/**
75+
* Is safe.
76+
*
77+
* @var bool
78+
*/
79+
protected $_isSafe = true;
7480

7581
/**
7682
* Request constructor.
@@ -208,8 +214,8 @@ public function protocolVersion()
208214
public function host($without_port = false)
209215
{
210216
$host = $this->header('host');
211-
if ($host && $without_port && $pos = \strpos($host, ':')) {
212-
return \substr($host, 0, $pos);
217+
if ($host && $without_port) {
218+
return preg_replace('/:\d{1,5}$/', '', $host);
213219
}
214220
return $host;
215221
}
@@ -656,14 +662,23 @@ public function __toString()
656662
return $this->_buffer;
657663
}
658664

665+
/**
666+
* __wakeup.
667+
* @return void
668+
*/
669+
public function __wakeup()
670+
{
671+
$this->_isSafe = false;
672+
}
673+
659674
/**
660675
* __destruct.
661676
*
662677
* @return void
663678
*/
664679
public function __destruct()
665680
{
666-
if (isset($this->_data['files'])) {
681+
if (isset($this->_data['files']) && $this->_isSafe) {
667682
\clearstatcache();
668683
\array_walk_recursive($this->_data['files'], function($value, $key){
669684
if ($key === 'tmp_name') {

Protocols/Http/Session.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ class Session
134134
*/
135135
protected $_sessionId = null;
136136

137+
/**
138+
* Is safe.
139+
*
140+
* @var bool
141+
*/
142+
protected $_isSafe = true;
143+
137144
/**
138145
* Session constructor.
139146
*
@@ -402,13 +409,25 @@ public function gc()
402409
static::$_handler->gc(static::$lifetime);
403410
}
404411

412+
/**
413+
* __wakeup.
414+
* @return void
415+
*/
416+
public function __wakeup()
417+
{
418+
$this->_isSafe = false;
419+
}
420+
405421
/**
406422
* __destruct.
407423
*
408424
* @return void
409425
*/
410426
public function __destruct()
411427
{
428+
if (!$this->_isSafe) {
429+
return;
430+
}
412431
$this->save();
413432
if (\rand(1, static::$gcProbability[1]) <= static::$gcProbability[0]) {
414433
$this->gc();

Worker.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Worker
3434
*
3535
* @var string
3636
*/
37-
const VERSION = '4.0.45';
37+
const VERSION = '4.0.46';
3838

3939
/**
4040
* Status starting.
@@ -1057,7 +1057,10 @@ protected static function formatStatusData($statistics_file)
10571057
}
10581058
$status_str = '';
10591059
$current_total_request = array();
1060-
$worker_info = \unserialize($info[0]);
1060+
$worker_info = [];
1061+
try {
1062+
$worker_info = unserialize($info[0], ['allowed_classes' => false]);
1063+
} catch (Throwable $exception) {}
10611064
\ksort($worker_info, SORT_NUMERIC);
10621065
unset($info[0]);
10631066
$data_waiting_sort = array();

0 commit comments

Comments
 (0)