PHP Classes
elePHPant
Icontem

PHP Cache Server: Store and retrieve cached data in a network server

Recommend this page to a friend!
  Info   View files Documentation   View files View files (39)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-09-17 (2 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 143 This week: 28All time: 8,650 This week: 14Up
Version License PHP version Categories
phpcache 0.9GNU General Publi...5Networking, PHP 5, Databases, Cache, P...
Description Author

This package can store and retrieve cached data in a network server.

It can work as a client and a server that takes TCP connection requests and can store and retrieve data a in a cache container.

The client may request to store, retrieve and delete data in a cache container on the server by sending a request over a TCP connection.

The server handles the TCP request by executing the requested cache operation using arrays as storage container.

Innovation Award
PHP Programming Innovation award winner
July 2018
Winner
There are several products that allow caching data very quickly and can be accessed via a local network connection.

This package can work as a client and server to store data a in a cache container that uses PHP arrays in memory for fast cache data access.

Manuel Lemos
  Performance   Level  
Name: Krisztián Dudás <contact>
Classes: 1 package by
Country: Hungary Hungary
Age: 26
All time rank: 407240 in Hungary Hungary
Week rank: 20 Up1 in Hungary Hungary Up
Innovation award
Innovation award
Nominee: 1x

Winner: 1x

Details

StyleCI Scrutinizer Code Quality Build Status

php-cache

Cache implementation for php

Usage:

Prequests:

  • PHP 5/7
  • composer #### Installing via composer: ` composer require kdudas/php-cache ` #### Supperted data types:
  • String
  • Integer/Float/Double
  • Array (serialized)
  • Objects (serialized) #### Creating a new server instance ` <?php

ini_set('log_errors', 1); ini_set('error_log', '/var/log/php-cache.log'); require_once 'vendor/autoload.php';

use PhpCache\CacheServer\CacheServer; use PhpCache\ServiceManager\ConfigAggregator; use PhpCache\ServiceManager\ServiceManager; // You can import multiple config files to overwrite parameters in the basic config or add extra factories $config = include_once 'config.php'; $configAggregator = new ConfigAggregator(); $configAggregator->addConfig($config); $serviceManager = new ServiceManager($configAggregator->getMergedConfig()); $server = $serviceManager->get(CacheServer::class); $server->run();

#### Running the server:

php testServer.php

#### OR

mv daemon.sh /etc/init.d/php-cache chmod +x /etc/init.d/php-cache

in this case you have to make the phar file globally executable because the daemon file will run it before stopping the service

create a directory called 'phar-build' -> copy the vendor and src folders to it -> copy the phpCache file to the directory -> run pharBuilder.php.

mv php-cache.phar /usr/local/bin/php-cache chmod +x /usr/local/bin/php-cache

now you can use systemctl style service management

sudo service php-cache start

##### Note 1: you can modify the contents of `daemon.sh` if you want to use other directories
##### Note 2:  A `.phar` file is a php archive file, which packs a php application into one file. If the sources or the config changes, it needs to be rebuilt! 

#### Adding Server Event Listeners:
- Create a config file that looks like this: 

<?php use PhpCache\CacheServerInter; use Example\ExampleEventListener; use Example\ExampleEventListenerFactory; return [

'services' => [
    'aliases' => [
        'PhpCache\CacheEventListener\CacheEventListenerInterface::class' => Example\ExampleEventListener::class
    ],
    'factories' => [
        'Example\ExampleEventListener::class' => ExampleEventListenerFactory::class
    ]
]

]

- Create the event listener class:
<?php
namespace Example;
use PhpCache\CacheEventListener\CacheEventListenerInterface;

class ExampleEventListener implements CacheEventListenerInterface
{
    //implement the abstract methods, add custom constructor with extra services (like db adapter, logger, etc...)
}
- Create the factory for the event listener class:

<?php namespace Example;

class ExampleEventListenerFactory {

public function __invoke($container)
{
    //Get the extra service you want from the container here and add add them to the constructor call
    return new ExampleEventListener();
}

}


#### Creating a new client instance

<?php include_once('vendor/autoload.php');

use PhpCache\CacheClient\CacheClient; use PhpCache\ServiceManager\ServiceManager;

$config = require_once 'config.php'; $serviceManager = new ServiceManager($config); /@var $client CacheClient/ $client = $serviceManager->get(CacheClient::class); $client->set('test', 'ASD'); echo $client->get('test');

##### You can run the client either from browser or console

php testClient.php

#### CLI Commands:
`./php-cache.phar get <key>` gets entries for the specified key. If no key is specified, it returns all entries.  
`./php-cache.phar set <key> <value>` pushes an entry to the cache pool with the given key - value pair.  
`./php-cache.phar delete <key>` deletes the entry with with the given key  
  Files folder image Files  
File Role Description
Files folder image.phan (1 file)
Files folder imagesrc (7 directories)
Plain text file composer.json Data Auxiliary data
Plain text file composer.lock Data Auxiliary data
Plain text file config.php Conf. Configuration script
Plain text file daemon.sh Data Auxiliary data
Plain text file LICENSE Lic. License text
Plain text file parallel_commands.sh Data Script to create parallel connections to server socket (for stress testing purposes)
Plain text file pharBuilder.php Example Example script
Plain text file phpCache Example Example script
Plain text file README.md Doc. Documentation
Plain text file testClient.php Example Class source
Plain text file testServer.php Example Class source

  Files folder image Files  /  .phan  
File Role Description
  Plain text file config.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageCacheClient (3 files)
Files folder imageCacheEventListener (2 files)
Files folder imageCacheServer (4 files)
Files folder imageCommands (4 files)
Files folder imageIO (2 files, 1 directory)
Files folder imageServiceManager (3 files, 1 directory)
Files folder imageStorage (5 files, 1 directory)

  Files folder image Files  /  src  /  CacheClient  
File Role Description
  Plain text file CacheClient.php Class Class source
  Plain text file CacheClientFactory.php Class Class source
  Plain text file ClientInterface.php Class Class source

  Files folder image Files  /  src  /  CacheEventListener  
File Role Description
  Plain text file CacheEventListenerInterface.php Class Class source
  Plain text file CacheEventListenerInterface.php Class Class source

  Files folder image Files  /  src  /  CacheServer  
File Role Description
  Plain text file ActionHandler.php Class Class source
  Plain text file CacheServer.php Class Class source
  Plain text file CacheServerFactory.php Class Class source
  Plain text file CacheServerInterface.php Class Class source

  Files folder image Files  /  src  /  Commands  
File Role Description
  Plain text file DeleteCommand.php Class Added console comma
  Plain text file GetCommand.php Class Added console comma
  Plain text file QuitCommand.php Class Class source
  Plain text file SetCommand.php Class Added console comma

  Files folder image Files  /  src  /  IO  
File Role Description
Files folder imageException (2 files)
  Plain text file CacheIOHandler.php Class Class source
  Plain text file CacheIOHandlerFactory.php Class Class source

  Files folder image Files  /  src  /  IO  /  Exception  
File Role Description
  Plain text file InvalidConfigException.php Class Class source
  Plain text file IOException.php Class Class source

  Files folder image Files  /  src  /  ServiceManager  
File Role Description
Files folder imageException (1 file)
  Plain text file ConfigAggregator.php Class Class source
  Plain text file ConfigAggregator.php Class Class source
  Plain text file ServiceManager.php Class Dependency injection logic

  Files folder image Files  /  src  /  ServiceManager  /  Exception  
File Role Description
  Plain text file NotFoundException.php Class Class source

  Files folder image Files  /  src  /  Storage  
File Role Description
Files folder imageException (1 file)
  Plain text file Bucket.php Class Class source
  Plain text file BucketFactory.php Class Class source
  Plain text file Maintainer.php Class Class source
  Plain text file MaintainerFactory.php Class Class source
  Plain text file StorageInterface.php Class Class source

  Files folder image Files  /  src  /  Storage  /  Exception  
File Role Description
  Plain text file StorageException.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:143
This week:28
All time:8,650
This week:14Up