Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
OpenSwoole table is a high performance memory management module, implemented based on shared memory and spin lock. It can be used by multiple processes: worker process or task worker process.
One row can be modified and accessed by multiple threads or processes. Global variables can be shared or used by multiple OpenSwoole Worker processes.
OpenSwoole table provides a two dimensions memory table for developers.
For performance reason, from v4.7.0, you can't use object of type OpenSwoole\Table as array.
OpenSwoole\Table->__construct
OpenSwoole\Table->column
OpenSwoole\Table->create
OpenSwoole\Table->destroy
OpenSwoole\Table->set
OpenSwoole\Table->get
OpenSwoole\Table->count
OpenSwoole\Table->del
OpenSwoole\Table->exists
OpenSwoole\Table->incr
OpenSwoole\Table->decr
OpenSwoole\Table->getMemorySize
OpenSwoole\Table->offsetExists
OpenSwoole\Table->offsetGet
OpenSwoole\Table->offsetSet
OpenSwoole\Table->offsetUnset
OpenSwoole\Table->rewind
OpenSwoole\Table->next
OpenSwoole\Table->current
OpenSwoole\Table->key
OpenSwoole\Table->valid
OpenSwoole\Table\Row->offsetExists
OpenSwoole\Table\Row->offsetGet
OpenSwoole\Table\Row->offsetSet
OpenSwoole\Table\Row->offsetUnset
For performance reason, from v4.7.0, you can't use object of type OpenSwoole\Table as array.
<?php
$table = new OpenSwoole\Table(1024);
$table->column('name', OpenSwoole\Table::TYPE_STRING, 64);
$table->column('id', OpenSwoole\Table::TYPE_INT, 4); //1,2,4,8
$table->column('num', OpenSwoole\Table::TYPE_FLOAT);
$table->create();
$table->set('a', array('id' => 1, 'name' => 'swoole-co-uk', 'num' => 3.1415));
$table->set('b', array('id' => 2, 'name' => "swoole-uk", 'num' => 3.1415));
$table->set('[email protected]', array('id' => 3, 'name' => 'swoole', 'num' => 3.1415));
var_dump($table->get('a'));
var_dump($table->get('b', 'name'));
More OpenSwoole Table Example: /docs/modules/swoole-table-example
The iterator and countable depends on pcre-devel
<?php
foreach($table as $row) {
var_dump($row);
}
echo count($table);