This repository has been archived by the owner on Sep 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 390
3. Data Sharing
Albert Chen edited this page Apr 29, 2018
·
11 revisions
Like what I said in the structure chapter, Laravel applications runs in different worker processes. There's one important concept you need to understand: Variables can not shared across different processes
.
Each worker will have their own varaibles and memory allocations. So keeping Laravel in memory doesn't mean you can share data among different processes.
You have few options if you really want to do in this package:
- Databases like MySQL or Redis
- APCu - APC User Cache
- Swoole Table
- Any other I/O based alternatives
In swoole_http.php
, you can customize your own swoole tables:
use Swoole\Table;
'tables' => [
// define your table name here
'table_name' => [
// table rows number
'size' => 1024,
// column name, column type and column type size are optional for int and float type
'columns' => [
['name' => 'column_name1', 'type' => Table::TYPE_INT],
['name' => 'column_name2', 'type' => Table::TYPE_STRING, 'size' => 1024],
]
],
]
There are three column types of Swoole table:
- TYPE_INT: 1,2,4,8
- TYPE_FLOAT: 8
- TYPE_STRING: the nth power of 2
<?php
namespace SwooleTW\Http\Table\Facades\Table;
class Foo
{
Table::get('table_name')->set('key', 'value');
Table::get('table_name')->get('key');
}
You can check more table usages here: https://www.swoole.co.uk/docs/modules/swoole-table