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 391
3. Data Sharing
Albert Chen edited this page May 2, 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
use SwooleTW\Http\Table\Facades\Table;
class Foo
{
// get a table by its name
$table = Table::get('table_name');
// update a row of the table by key
$table->set('key', 'value');
// get a row of the table by key
$table->get('key');
// delete a row of the table by key
$table->del('key');
// check if a row is existed by key
$table->exist('key');
// count the rows in the table
$table->count();
}
You can check more table usages here: https://www.swoole.co.uk/docs/modules/swoole-table