PHP Classes

Q PHP Storage Class: Store data objects using Swoole tables

Recommend this page to a friend!
  Info   View files Documentation   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Last Updated Ratings Unique User Downloads Download Rankings
2022-05-28 (5 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 50 This week: 1All time: 10,355 This week: 491Up
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 walid laggoune
  Performance   Level  
Name: walid laggoune <contact>
Classes: 7 packages by
Country: Algeria Algeria
Age: 21
All time rank: 27993 in Algeria Algeria
Week rank: 587 Up1 in Algeria Algeria Up
Innovation award
Innovation award
Nominee: 2x

Details

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  
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  /  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  /  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  /  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  /  src  /  Exceptions  
File Role Description
  Plain text file NotEnoughSpaceException.php Class Class source

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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:50
This week:1
All time:10,355
This week:491Up