PHP Classes

Q PHP Storage Class: Store data objects using Swoole tables

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 60 This week: 1All time: 10,495 This week: 34Up
Version License PHP version Categories
qphp-storage 1.0MIT/X Consortium ...8Databases, Web services, Design Patterns, P...
Description 

Author

This package can store data objects using Swoole tables.

It provides a base class that can perform several types of operations to store and retrieve the values of objects that are made of named properties using tables managed by Swoole.

Currently it can:

- Create a table of a given size store store the objects

- Store data for an object with a given key

- Get the data of an object with a given key

- Check if an object with a given key exists

- Delete the object with a given key

- Use a custom cast class that can convert this class objects in JSON strings or other formats

Innovation Award
PHP Programming Innovation award nominee
May 2022
Number 7
Swoole is an Open Source project that allows developers to create PHP applications that can execute operations asynchronously and quickly.

This way, applications can execute multiple operations simultaneously in parallel, so a single PHP script can run in less time than the same script would execute using the regular PHP implementation.

This package uses Swoole speed optimization to implement a client that can store objects in a storage container managed by a server executed using Swoole.

This package can store and retrieve data objects faster than using traditional types of databases used by PHP developers that require clients to wait until the database access queries finish before the PHP scripts move to execute the next operation in the same PHP script.

Manuel Lemos
Picture of LAGGOUNE Walid
  Performance   Level  
Name: LAGGOUNE Walid <contact>
Classes: 8 packages by
Country: Algeria Algeria
Innovation award
Innovation award
Nominee: 3x

Documentation

QPHP-storage

A simple storage library uses swoole table. <br/> This library is built to work with queue php swoole server. but it is available as component to use it whenever you want.

Requirements

  • PHP > 8.0.2
  • swoole > 4.8

Example

<?php
require "vendor/autoload.php";

use QPStorage\Base\Storage;
use QPStorage\Casts\JsonCast;

class UserStorage extends Storage {

	// Required
	public string $name 		= 	"users";
	// Required
	public int $size 			= 	1024;
	// Required
	public array $definitions 	= [
		"id" 		=> 		[Swoole\Table::TYPE_INT],
		"name" 		=> 		[Swoole\Table::TYPE_STRING, 64],
		"options" 		=> 		[Swoole\Table::TYPE_STRING, 64]
	];
	// Optional , if you do not need it , remove the property
	public array $casts 	= [
		// You are free to use your own casters , but you should implement QPStorage\Casts\CastInterface
		"options" => JsonCast::class
	];

}

Get the results

<?php
$users = new UserStorage;
$users->put("foo", ["id" => 1, "name" => "foo", "options" => ["age" => 22]]);
$users->put("bar", ["id" => 2, "name" => "bar", "options" => ["age" => 24]]);

echo $users->get("foo")->options["age"];
// Loop over users

$users->rewind();
while($users->valid()) {
	$user = $users->current();
	echo $user->name."\n";
	$users->next();
}

Custom casts

<?php 

namespace QPStorage\Casts;

class JsonCast implements CastInterface {

	public function set($data) {
		$data = json_encode($data);
		return (JSON_ERROR_NONE !== json_last_error()) ? "" : $data;
	}

	public function get($data) {
		 $data = json_decode($data, true);
		return (JSON_ERROR_NONE !== json_last_error()) ? [] : $data;
	}

}

  Files folder image Files (10)  
File Role Description
Files folder imagesrc (1 file, 3 directories)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file readme.md Doc. Read me

  Files folder image Files (10)  /  src  
File Role Description
Files folder imageBase (2 files)
Files folder imageCasts (2 files)
Files folder imageExceptions (1 file)
  Plain text file StorageInterface.php Class Class source

  Files folder image Files (10)  /  src  /  Base  
File Role Description
  Plain text file Storage.php Class Class source
  Plain text file StorageIterator.php Class Class source

  Files folder image Files (10)  /  src  /  Casts  
File Role Description
  Plain text file CastInterface.php Class Class source
  Plain text file JsonCast.php Class Class source

  Files folder image Files (10)  /  src  /  Exceptions  
File Role Description
  Plain text file NotEnoughSpaceException.php Class Class source

  Files folder image Files (10)  /  tests  
File Role Description
  Plain text file TableTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:60
This week:1
All time:10,495
This week:34Up